Ver Mensaje Individual
  #12 (permalink)  
Antiguo 15/02/2009, 03:39
Avatar de MeduZaPaT
MeduZaPaT
 
Fecha de Ingreso: enero-2009
Ubicación: USA
Mensajes: 106
Antigüedad: 15 años, 3 meses
Puntos: 3
Respuesta: Donde bajar librerias para C++

sos terco y encima necio, no queres ver lo que quiero decir y saltas con cosas que no son, el pibe esta escribiendo codigo de cero y vos saltas con programas ya echos que es otro tema aparte.
Si vas a empezar de cero algo y lo vas a hacer en C++ ¿para que lo vas a escribir en C? si queres aprender C++ escribis en C++ y punto, sino aprende C y listo, es asi, es como querer dejar de fumar fumando!!

no entendes lo que se plantea aca y encima me decis a mi que soy el que no entiende, entendi todo esto antes que vos y vos aun no lo entendes.


Cita:
Iniciado por Eternal Idol Ver Mensaje
Esto ultimo es una soberana estupidez que es mucho mejor ni siquiera responder pero te voy a hacer un favor demostranos el leak aca:

Código:
char *buffer = new char[1024];
free(buffer);
Se nota que queda mucho por explicar que NO sabes.
que ejemplo facil mescla algo con clases a ver como te va, se ve que no controlas liqueos de memoria en el codigo que escribis, ojo con eso que es un error grabe.

de google porque no me voy a ponerlo a tipiar del libro:
Cita:
new/delete

* Allocate/release memory
* Returns a fully typed pointer.
* new (standard version) never returns a NULL (will throw on failure)
* Are called with Type-ID (compiler calculates the size)
* Has a version explicitly to handle arrays.
* Reallocating (to get more space) not handled intuitively (because of copy constructor).
* If they call malloc/free is implementation defined.
* Can add a new memory allocator to deal with low memory (set_new_handler)
* operator new/delete can be overridden legally
* constructor/destructor used to initialize the object

malloc/free

* Allocates/release memory
* Returns a void*
* Returns NULL on failure
* Must specify the size required in bytes.
* Allocating array requires manual calculation of space.
* Reallocating larger chunk of memory simple (No copy constructor to worry about)
* They will NOT call new/delete
* No way to splice user code into the allocation sequence to help with low memory.
* malloc/free can NOT be overridden legally

Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()?

No!

It is perfectly legal, moral, and wholesome to use malloc() and delete in the same program, or to use new and free() in the same program. But it is illegal, immoral, and despicable to call free() with a pointer allocated via new, or to call delete on a pointer allocated via malloc().

Beware! I occasionally get e-mail from people telling me that it works OK for them on machine X and compiler Y. Just because they don't see bad symptoms in a simple test case doesn't mean it won't crash in the field. Even if they know it won't crash on their particular compiler doesn't mean it will work safely on another compiler, another platform, or even another version of the same compiler.

Beware! Sometimes people say, "But I'm just working with an array of char." Nonetheless do not mix malloc() and delete on the same pointer, or new and free() on the same pointer! If you allocated via p = new char[n], you must use delete[] p; you must not use free(p). Or if you allocated via p = malloc(n), you must use free(p); you must not use delete[] p or delete p! Mixing these up could cause a catastrophic failure at runtime if the code was ported to a new machine, a new compiler, or even a new version of the same compiler.

You have been warned.
estas mesclando funciones de alto nivel u objetos con las de bajo nivel y eso hace una ensalada terrible, ademas de que con new no solo pedis memoria... investigalo, quisas nunca saliste de una sola plataforma y de un solo compilador que se yo, o tuviste suerte :P

Última edición por MeduZaPaT; 15/02/2009 a las 04:02