I have the source for a large (>250 files) library that makes heavy use of STL containers and strings. I need to run it in an embedded environment with limited heap, so I want to ensure that this library itself is limited in its heap usage.

The obvious solution is to create an allocator, but modifying the entire code base to include the allocator template parameter is a big job of last resort, and undesirable in case I ever want to take a new version of the source. Globally replacing new and delete is not feasible since that affects the entire image, not just this library.

My next thought was a stupid C macro trick, but that doesn't seem like it would be possible, although I admit to not being a clever macro author.

So I thought "is there a compiler or pragma switch to specify the allocator<> class at compile time"? But I'm open for anything.

The next question I'll ask, if anyone can come up with a solution, is how to do the same for new/delete within the set of files comprising this library.

I'm using the gcc 3.4.4 toolchain to run this under Cygwin, with a target of VxWorks, if that sparks any ideas.

Edit
Report