|
Boost : |
From: Boris (boriss_at_[hidden])
Date: 2006-06-17 12:12:39
I have a problem with ordered_malloc() and ordered_free() which might be
from misunderstanding the documentation. I use these two functions to
overload operator new[] and operator delete[]:
template <class T>
class mem_manager
{
protected:
static boost::pool<my_allocator> mem_pool;
public:
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); }
};
I overloaded new and delete with malloc() and free() which works fine.
However from what I understand I can't use them for new[] and delete[] -
that's why I tried ordered_malloc() and ordered_free(). 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 list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk