I cannot say exactly what is happening, but the problem (if it is a problem) is reproducible.
I thought it was a memory pool problem, wandering that the STL was doing this in the particular allocator used. However, the drilldown list <>, I found only "new_allocator", which returns nothing more, returning the result of the global new operator:
pointer allocate(size_type __n, const void* = 0) { return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); }
The behavior, as I understand it, then goes to glibc or stdlibC ++. In my quick look, I could not figure out how to get around this behavior without implementing a custom allocator, and if the custom allocator will certainly behave differently.
I tried another test without STL, and then I could see how resources grow. I would suggest creating your own distributor, which allocates an arbitrary number of elements in the array with the placement of a new one and takes care of the distribution / deallocation of these arrays. Logic tells me that resource use should behave the same as the "non STL" test.
Please try and tell what will happen. I won’t do it myself, because I don’t have time to get rid of it now, despite my curiosity;)
Note: The Big Three rule is not affected here. As far as I understand, there is no memory leak, and the contents of the object does not matter. Bruno could make a copy of the data, homing, etc., but just created an empty constructor to illustrate his point.
source share