Efficiency of using array as stack

Ivan Kazmenko gassa at mail.ru
Mon Mar 25 16:34:57 PDT 2013


> You will likely get better performance if you use:
>
> a ~= int.init;
>
> instead of:
>
> a.length++;

So that's a relief, a dynamic array in D actually *is* an 
efficient queue implementation out of the box, I just did it 
improperly in the example.  Thank you for the correction.  With 
that, the number of relocations in the queue example dropped down 
to 2.

> growth of 1024 is when the new pages are tacked onto the end 
> (4096 / sizeof(int)), growth of 891 is interesting.  I can 
> explain it though :)

Thank you for the very detailed explanation!  Knowing how things 
work down to the bare bones, and the rationale behind that, is 
definitely helpful, both logically (to write better code) and 
psychologically (the feeling of things in control).  I just hope 
such quality explanations will be incorporated into some book or 
manual someday.

-----
Ivan Kazmenko.


More information about the Digitalmars-d-learn mailing list