attaching an STL Allocator interface

M

Mark P

I'm working with a system which has its own memory manager. Any class
which uses the system defines operator new and operator delete in the
following way:

void* operator new(size_t size) {return(memMgr.allocate(size));}
void operator delete(void *p) {memMgr.free(p);}

Here memMgr is some global object which does all the behind-the-scenes
work, taking care of things like memory pools, disk swapping certain
objects, etc.

What I'd like to do is make STL classes use this same underlying memory
manager. If I understand things right, this means I need to basically
build an Allocator which will call these memMgr.allocate and memMgr.free
fcns. (Unbelievably, nobody using this system uses STL classes so this
issue has never previously arisen.)

I'm looking for suggestions on where to find sample code implementing
STL allocators and also any general advice on undertaking this,
especially if there are any critical issues that make this idea
impossible. My naive feeling is that this shouldn't be very hard, since
the Allocator doesn't really do much except forward a couple calls, and
yet having never written an Allocator I'm a little overwhelemed by the
details in TC++PL.

Thanks for your help,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top