How do you remove/insert elements in a dynamic array without allocating?
Jonathan M Davis
jmdavisProg at gmx.com
Mon Nov 5 17:35:28 PST 2012
On Tuesday, November 06, 2012 02:27:24 bearophile wrote:
> void main() {
> auto array = [1, 2, 3, 4, 5];
> array.assumeSafeAppend();
> foreach (i; 0 .. 10_000_000) {
> array.length--;
> array ~= i;
> }
> }
assumeSafeAppend needs to be called every time that length is decremented. It
does nothing in this example, because when it's called, array is already
marked as the last slice in its block.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list