Boost logo

Boost :

From: Brad Spencer (spencer_at_[hidden])
Date: 2002-10-17 15:19:27

I have an application that allocates memory using a pool and then
often frees the entire pool using purge_memory(), but then reuses the
same pool again to allocate more. The algorithm looks as follows:

  1. Allocate a bunch of memory from pool
  2. Call purge_memory()
  3. Goto 1

After a brief period of time, the pool is calling the UserAllocator
with a request of just over 1 GB (0x4000000C). The pool's requested
size is 32 K. It would appear that neither purge_memory() nor
release_memory() reset the next_size back to its original setting.

Because next_size exponentially grows (by doubling) every time a new
allocation is required from the UserAllocator, this calling pattern
quickly leads to an attempt to allocate more memory than is available
in the system.

By calling set_next_size(32) [since 32 is the initial value of
next_size] after each call to purge_memory(), I have
been able to work around this problem, leading me to believe that this
is actually a bug.

Also, perhaps next_size should grow by a factor of 1.5 instead 2, as
is suggested by Andrei Alexandrescu in "Modern C++ Design" (I don't have
the page handy :)

Brad Spencer - spencer_at_[hidden] - "It's quite nice..."
Systems Architect | InfoInterActive Corp. | A Canadian AOL Company

Boost list run by bdawes at, gregod at, cpdaniel at, john at