Re:Zeroing Memory is Hard: VC++ 2015 arrays
by honkhonkpants on Monday July 18, 2016 @03:22AM
(#12113632)
What was the solution? Using a custom allocator?
[ Parent
| on HN ]
Re:Zeroing Memory is Hard: VC++ 2015 arrays
by deadmutex on Monday July 18, 2016 @05:29AM
(#12114012)
I 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.
Re:Zeroing Memory is Hard: VC++ 2015 arrays
by brucedawson on Monday July 18, 2016 @11:26AM
(#12115611)
In 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.
Re:Zeroing Memory is Hard: VC++ 2015 arrays
by someguydave on Monday July 18, 2016 @08:31AM
(#12114647)
Yes 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.
A 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.
Re:Zeroing Memory is Hard: VC++ 2015 arrays
by SeanBoocock on Monday July 18, 2016 @08:30PM
(#12118790)
This 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".