This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: std::map allocations questions
>> With the appropriate overloading of new function.
>
> I can only guess what you consider "appropriate" but obviously
> std::map allocates memory internally, so if you have replaced the
> global new operator, then it will get called recursively.
>
> This is not a problem with std::map, it's just unavoidable that a
> container using dynamically-allocated memory will have to allocate
> memory!
>
You can use std::map inside new/malloc but you need to provide a
custom allocator (see full specification of the std::map template
class) that does not rely itself on malloc. So you'd have to
implement the interface of
http://www.cplusplus.com/reference/std/memory/allocator without
malloc. Depending on your system, you may be able to do so using
sbrk/mmap and managing free lists internally.
Silvius