Reputation: 1268
I have written a memory allocator to solve a problem with the speed of the default one in C++ (mingw).
To do this I've overloaded global new and delete. All the requests i'm getting through are being correctly allocated with memory of the correct sizes but i'm still getting segmentation faults. These faults seem to be about the use of vectors.
I assume these vectors would be covered by the global override of new and delete but I maybe wrong. So what i'm asking is would I need to have an stl allocator that works off of my memory allocator or is it likely some other problem using global new and delete that I have overlooked?
Upvotes: 4
Views: 345
Reputation: 70037
I assume these vectors would be covered by the global override of new and delete but I maybe wrong. So what i'm asking is would I need to have an stl allocator that works off of my memory allocator or is it likely some other problem using global new and delete that I have overlooked?
The C++ Standard (here from C++11) says about std::allocator
(the default allocator used for standard containers):
(§20.6.9/1) Remark: the storage is obtained by calling ::operator new(std::size_t) (18.6.1), but it is unspecified when or how often this function is called. [...]
So the fact that you didn't implement a special allocator class for use with the vectors is not a problem. The problem is probably caused by something wrong about your definition of the global operator itself, or perhaps about the way you use the vectors. Recommended next steps are:
::operator new
is not replacedUpvotes: 5
Reputation: 31972
I believe STL Allocators would need to be implemented for you to control vector
s allocations
Upvotes: 0