I am trying to replace global new ones and delete operators with Xcode 3.2, GCC 4.2, libstdC ++ 4.0, the dynamic version.
I took the prototypes directly from the "new" header and implemented them. They are inserted below.
The project is .plugin, thus a dynamic lib. This plugin SHOULD delegate allocation to main applications of their own alloc / free algorithms, which are in the old SDK SDK.
All my own calls to new / delete along with the values of std :: list and std :: map are correctly replaced, but not when std :: vector :: push_back should grow its buffer. In this case, my new operator is not called, but my operator is deleted. I know this because I write the token in the first four bytes of any buffer allocated by my new statement, and I check this token in deleting the statement. Below is the violation code.
extern "C++"
{
__attribute__((visibility("default"))) void* operator new(std::size_t) throw (std::bad_alloc);
__attribute__((visibility("default"))) void* operator new[](std::size_t) throw (std::bad_alloc);
__attribute__((visibility("default"))) void operator delete(void*) throw();
__attribute__((visibility("default"))) void operator delete[](void*) throw();
__attribute__((visibility("default"))) void* operator new(std::size_t, const std::nothrow_t&) throw();
__attribute__((visibility("default"))) void* operator new[](std::size_t, const std::nothrow_t&) throw();
__attribute__((visibility("default"))) void operator delete(void*, const std::nothrow_t&) throw();
__attribute__((visibility("default"))) void operator delete[](void*, const std::nothrow_t&) throw();
}
The following code will trigger an assertion when "yo" goes out of scope because the memory allocated for std :: vector was not assigned by my new operator.
{
std::vector<std::string> yo;
yo.push_back("yoyoma");
yo.push_back("yoyoma");
yo.push_back("yoyoma");
yo.push_back("yoyoma");
}
The following code is fine, because std :: vector :: reserve calls my new operator:
{
std::vector<std::string> yo;
yo.reserve(4);
yo.push_back("yoyoma");
yo.push_back("yoyoma");
yo.push_back("yoyoma");
yo.push_back("yoyoma");
}
GBD () std::vector:: push_back, ( _M_insert_aux). , , , new std::vector:: push_back.
, . - push_back.
libstd++. a, .
- std::vector < std::string > , ?
, Windows VS9.