On 10/09/2010 15:21, Tang Jiang Jun wrote:
Such as any, asio, etc.
But redefining global new operator is dangerous
How so?
and prone to conflict with global static objects which use the memory heap before custom memory heap manager get initialization.
Then initialize your heap manager first, or initialize it at the first allocation, or upon allocation, check whether it is initialized and if it isn't, fallback to some other allocation mechanism. You said you wanted all objects to be allocated using a particular function: the easiest way to achieve that is to replace the default allocation function by that you want to use.
Actually why do most of boost libraries not provide the allocator interface to help users to manage their memory, as the way STL offers?
While it makes sense for containers, and eventually for any, I don't see why it is really important in general. Asio allocating memory behind the scenes to do its work is fine as long as it's small, fixed, and doesn't appear to the user. Taking allocators wouldn't hurt, but I'm unsure that's necessary for fairly high-level libraries, where there isn't even a notion of what the memory would be used for.