
On 9 Jun 2009, at 13:34, Christian Schladetsch wrote:
The following code assertss for me, g++ 4 on Mac OS X. Notice how I only need to do 33 iterations.
I will get back to you. No, I havent done exhaustive cross-platform testing but this is suprising and indicates a basic fault. I use Ubuntu by default.
I find the code breaks identically on Ubuntu and Windows. Furthermore, I'm afraid to say I'm sure this is unfixable. vector requests a new block of memory, copies data across, and then frees the old block. You can't make it do what you want to. You could, either in your wrapper do a .reserve() for the appropriate amount of memory, but that's certainly not guaranteed by the standard to work in all cases -- I don't know if it would work in practice across multiple compilers. This would only work for vector, not the other containers, which would need their own fixes (for example most std::deques allocate in blocks of their own, large, predefined size, and also need a separate allocation for a "master list" of pointers). I imagine with std::set you might be better off, but then again that always does a fixed size allocation, so arguably there you would be better with an optimised fixed-size allocator, which can efficiently handle frees anyway. Chris
Ddo you have even a basic testing suite for this code? I couldn't find one, and this seems like a fairly fundamental bug. Perhaps it doesn't occur on windows?
#include "boost/monotonic/vector.h"
int main() { boost::monotonic::inline_storage<100*sizeof(int)> storage; // create local storage on the stack boost::monotonic::vector<int> deathrow(storage); // create a std::vector that uses this storage
for(int i = 0; i < 33; ++i) deathrow.push_back(i);
}
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Christian. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost