Re: freeing part of memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 05.01.2010 02:21, schrieb £ukasz:
Hi, i have simple question about freeing only part of allocated memory.
Supouse that at begining of computatnion i reserwed ( malloc,relloc, etc) n bytes, after end of compuation i need only n/2 bytes so i want to free the rest of n/2 bytes. I could ofcourse use freeloc(beg.adress+n/2) after creating in memory apropriate structure usualy created by malloc to force freeloc to free only n/2 bytes, but maybe there is another way, for example using new and delate.

Lukas




You use realloc with n/2. This will (very likely) in fact allocate in a new ram area, so you possibly want to copy over the data from the old allocated space. If you are done with the space you allocated first, you free the whole thing.

You cannot use "freeloc(beg.adress+n/2) " (assuming you mean free() here).

That's really a general C question, not a gcc related one.

Best regards.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux