Boost Pool C++ Question

I am using the Boost pool to try and solve a memory fragmentation/memory leak problem and have a question about the free and release_memory methods of the class.

Free is supposed to just return memory to the pool. Relase_memory, if I understand correctly, actually deallocates memory. Is this true? Because for reasons I won’t get into at the moment, my program crashes with an out of memory exception when I just call free, but I would thinki it wouldn’t crash if I always release memory, but it does crash exactly as in calling free.

A crash upon calling free() sounds a lot to me like some other code is writing past a buffer boundary and onto the adjacent data structures that the allocation code uses to define allocation sectors.

I haven’t used boost::pool myself, but going over the interface documentation, I would say that this is somewhat correct, though perhaps not a very precise description of what’s actually going on. A boost::pool object can contain multiple blocks of memory, each of which is segregated into a number of fixed-size chunks. The chunks are what you get when you call pool::malloc(), and pool::free() is what you use to return a chunk to the “free list” for the block it came from.

release_memory() doesn’t have anything to do with freeing chunks. Instead, it’s an operation on blocks: calling release_memory() will deallocate any blocks that are unused; i.e., any blocks that have no allocated chunks. If all the blocks in your pool have at least one chunk allocated, calling release_memory() will do nothing.

As for your crashing problem: I agree with Punoqllads that it’s probably a case of the allocation information being corrupted. Can you be more specific? You say you’re getting an “out of memory exception” – where exactly is this exception originating? I don’t think it’s possible for pool::free() to throw an exception, so knowing where it’s actually coming from would be very helpful in determining what the problem is.

So if you free all chunks for a given block, then calling release_memory will then deallocate that block?