Boost logo

Boost Users :

From: Boris (boriss_at_[hidden])
Date: 2006-06-17 08:00:30


I created a memory manager based on boost::pool and overloaded various
operators like this:

template <class T>
class mem_manager
{
protected:
 static boost::pool<my_allocator> mem_pool;

public:
 void *operator new(std::size_t) { return mem_pool.malloc(); }
 void operator delete(void *p) { mem_pool.free(p); }
 void *operator new(std::size_t, void *p) { return p; }
 void operator delete(void*, void*) { }
 void *operator new[](std::size_t size) { return
mem_pool.ordered_malloc(size / sizeof(T)); }
 void operator delete[](void *p) { mem_pool.ordered_free(p); }
};

Any class derived from mem_manager uses now its own boost::pool. While new
and delete work fine there is a problem with new[] and delete[]. I haven't
really investigated the problem yet because I'm not sure if I implemented
these two operators correctly or if I understood ordered_malloc() and
ordered_free() wrong. The documentation at
http://www.boost.org/libs/pool/doc/interfaces/pool.html says something about
merging free lists and preserving order with ordered_malloc(). Is this
related to allocating an array? Or how shall I implement new[] and delete[]
correctly?

Boris


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