Boost logo

Boost Users :

Subject: [Boost-users] [pool] Questions about memory pool
From: Junchao Zhang (junchao.zhang_at_[hidden])
Date: 2012-06-07 11:57:19


Hello,
  I'm new to boost memory pool. I have two questions:
  1) My program has multiple iterations. In each iteration, I need to
allocate chunks(objects) from a pool. I don't need to allocate array of
chunks. I don't free objects until the end of an iteration. Then what is
the most efficient way to do that? I wrote the following code, but I'm not
sure it is right.

    boost::pool<> p(sizeof(MyType));
    for (...) {
      ...
      // many calls to p.malloc();
      ...
     p.release_memory(); // Is it OK???
    }

Also, I was wondering, to improve locality, how to reuse the memory in the
next iteration, instead of deallocating/allocating memory again and again.

2) How to inquiry a pool to know have many objects have been allocated
from the pool? For example, if malloc() 2 times, free() 1 time, then the
count is 1. Does boost pool have this interface?

Thanks!

-- Junchao Zhang



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net