Optimization question

Jonathan Wakely jwakely.gcc@gmail.com
Tue Sep 27 17:10:00 GMT 2016


* Nikolaus Dunn:
> I've run into an issue where turning on compiler optimization using
> -O1 or higher causes an issue in my program. Specifically, I am
> replacing the new and delete operators globally to perform some real
> time allocation tracking. When I compile with -O1 or -O2, my
> implementation of new is not being called by STL classes, via the
> std::allocator. My version of delete IS being called.

That doesn't make much sense, because std::allocator<T> doesn't use
new or delete for objects of type T, so neither should be called.

Instead std::allocator<T> allocates untyped memory (e.g. via malloc)
and then constructs objects into it with placement new-expressions.

What do you replacement new and delete operators look like?



More information about the Gcc-help mailing list