std::map::insert
creates a map node that is a private structure containing a copy of the key and a copy of the value, and adjust some pointer according to the implementation requirement so that the node can be found when the key is specified and when the map itself is walked by iterators.
The creation / deletion of nodes happens through an instance of a
std::allocator
, by calling
allocate
and by calling a
placement new
on the returned space.
Vice versa, deletion is made by explicitly calling the node destructor, and then calling the allocator
deallocate
giving the memory back to it.
The purpose of atd::allocator is to allocate/deallocate uninitialized memory. The default implementation (used by std::map, if you don't specify anything else for it) is to allocate a chunk of bytes as a char[] using
new char[x]
, and returning tham to the system via
delete[]
.
Respect to your
operator new
, there is no "global" or "local" "overload".
void* operator new(size_t) is nothing more than a function whose prototype is declared in
<new>
and whose compiled body is placed into the C runtime library that is linked by default.
What you do is just provideng another implementation of that same function prototype into an OBJ file the linker will resolve before going to the default library. Hence the default library function is not anymore visible, and whatever compiled code (including the instance of the STL templates, since they instantiate into you own translation units) will refer to your function.
The point, now, is to make sure that you provided consistent and congruent overload for both
void* oeprator new(size_t)
and
void* operator new[](size_t)
since i may be you override one and the STL implementation is calling the other.
You also should override the correspondent
void operator delete(void*)
and
void operator delete[](void*)
It's not -in general- a good practice to overload the global new/delete (since it can lead to conflicts between libraries).
Consider a different syntax like the one you can obtain with
enum my_new_t { my_new };
void* operator new(size_t sz, my_new_t)
{
return ::operator new(sz);
}
that can be used as
A* pa = new(my_new)A;
That's clearly different that
new A
or
new(hes_new)A
.
An if you need another allocation scheme for STL classes, consider to write your own
allocator
class.