std.collection lets rename it into std,ridiculous.

H. S. Teoh hsteoh at
Mon Feb 20 10:11:18 PST 2012

On Mon, Feb 20, 2012 at 05:16:17PM +0100, a wrote:
> >Nope, it doesn't. That's the power of D slices. When you create a
> >dynamic array, the GC allocates a certain amount of memory, let's
> >call it a "page", and sets the array to point to the beginning of
> >this memory. When you append to this array, it simply uses up more of
> >this memory. No reallocation actually occurs until the page is used
> >up, at which point the GC allocates a larger page to store the array
> >in.
> Yes, it does. When you take a slice of an array and then append an
> element to it, the slice has to be reallocated or the element in the
> original array after the end of the slice would be modified.

I know that. But we're implementing a stack here. The stack slice is the
only thing that refers to that part of the memory. The reallocation only
happens if you start making external references to elements/slices on
the stack. But if you only access it via push() and pop(), then there
are no other references to the stack, so why should the GC reallocate it
on append?


Государство делает вид, что платит нам зарплату, а мы делаем вид, что работаем.

More information about the Digitalmars-d mailing list