3 ms·
What was the solution? Using a custom allocator?
by honkhonkpants 10y ago
What was the solution? Using a custom allocator?
- deadmutex 10y agoI am not OP, but you could get around it by having a default constructor that is empty. This might've not been possible if you need a different default constructor that initializes values.
- gpderetta 10y agoUsing a custom allocator is the standard-blessed solution for this problem, although it can be inconvenient.
- someguydave 10y agoYes you could use a custom allocator except that changes the type of the std::vector - making a large ripple in our code base. I have not solved it yet. The best solution - don't use std::vector for anything critical.
- brucedawson 10y agoIn my case the fix was to not allocate so much space. The vector was always being resized to 64 KiB. After considering lots of other options I decided that the most pragmatic fix was just a smaller constant to the vector constructor. I don't remember why the other options weren't practical.
- andreyv 10y agoA simple new int[] will work. It doesn't initialize the array (unlike the new int[]() version). You can use it with std::unique_ptr<> to simplify memory management.
- SeanBoocock 10y agoThis is true but at least with the current standard you will want to define a custom deleter with your unique_ptr to implement "delete [] data" vs the default behavior of "delete data".