Alex Rivera | Logout

Replace Standard C++ Allocator?

Asked 2012-11-07T05:45:15.097
11

I want to replace the standard allocator with a more robust allocator (the C++ standard only requires an overflow check on vector::resize). The various C++ allocators supplied with many libraries fall flat on their face when fed negative self tests.

I have access to a more robust allocator. ESAPI's allocator not only checks for overflow, it also has debug instrumentation to help find mistakes. http://code.google.com/p/owasp-esapi-cplusplus/source/browse/trunk/esapi/util/zAllocator.h.

Is there a standard way to replace the C++ allocator used in a program without too much effort? I also want to ensure its replaced in library code, which I may not have access to source code.

Edit
Report

1 Answer

4

In C++0x, define a new template alias in namespace mystd that is a std::vector but with your custom allocator. Replace all std::vectors with mystd::vector. Get rid of all using namespace std and using std::vector in your code.

Rebuild. Replace the places where you used a raw vector<T> with mystd::vector<T>.

Oh, and use a better name than mystd.

answered 2012-11-07T06:09:47.137

Your Answer