Apart from using mmapand munmapto eliminate excess that you do not need (or mremapthat can do the same, but non-standard), there is no way to reduce the size of the allocated memory block. And it mmaphas page granularity (usually 4k), so if you are not dealing with very large objects, using this will be worse than just leaving the objects larger and not compressing them at all.
With that said, reducing memory in place is probably not a good idea, since freed memory will be highly fragmented. A good implementation reallocwill want to move the blocks while significantly reducing them as a possibility of defragmenting the memory.
, , , , , , . , :
- , "" , .
- , , (
size_t ptrdiff_t) .
, , .
, , - , , .