Is this a bug? Or am I misunderstanding
something?

import std.stdio, std.string;
import std.array;

unittest {
    int[] a;
    a.reserve(10);
    a.length++;
    int *p = &(a[0]);

    a.length++; // Increase size. Shouldn't reallocate.
    int *p2 = &(a[0]);
    assert(p == p2); // And indeed it didn't.

// So sometime later, we want to reuse the allocation. We 'clear' it:
    a.length = 0;

    // ... and later start using it...
    a.length++;
    int *q = &a[0];
assert(p == q, format("p: %s; q: %s", p, q)); // FAILS! (on dmd 2.065.0) Why? Apparently, setting length to 0 caused it to free the // reserved allocation?
}


Reply via email to