Mail Archives: djgpp/2000/08/24/02:08:55
> From: Leon AT caresystems DOT com DOT au
> Date: Thu, 24 Aug 2000 09:30:03 +1000
>
> the problem is - how would one free memory that is a remainder of offset?
> for example say malloc returns 5 (pseudo example only) so then one
> modifies it to say 10...
> now the memory from location 5 to location 9 is theoretically not used
> and thus could be used when some other allocation needs to take place -
> the thing is - how can i free memory from locaton 5 to location 9
> keeping the rest (from loc 10 to whatever was allocated)...
You can't. The whole block must be freed as a single allocation.
If your application really needs to release those unused small chunks,
you will have to do your own allocation, for example, by allocating
large blocks that are aligned as you wish, and then subdividing them
as appropriate. When allocated blocks are large, the extra slack of a
few bytes is not important.
FWIW, most applications that need aligned memory don't need to bother
about the slack at all, since the number of such allocations is
usually small.
- Raw text -