Don't use arrays as stacks

Andrew Wiley wiley.andrew.j at gmail.com
Sun Sep 25 01:18:29 PDT 2011


On Sun, Sep 25, 2011 at 1:45 AM, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On Sunday, September 25, 2011 02:37:25 Nick Sabalausky wrote:
>> If anyone cares, I've put up a little thing about why it's best not to use
>> D's arrays as stacks. This is drawn from a direct experience a few months
>> ago. Figured if I fell into that trap then others might too, so this could
>> be helpful for some people. There's a no-login-needed comments section
>> already there.
>>
>> https://www.semitwist.com/articles/article/view/don-t-use-arrays-as-stacks
>
> Yeah. If you want to use an array for a stack, it really needs to be wrapped
> in a struct or class like you'd do in C++. Expanding it when the size of the
> array needs to increase to accomodate items pushed onto the stack is certainly
> much easier in D, but trying to use the array as a stack directly is definitely
> going to cause issues as you show in the article.
>
> - Jonathan M Davis
>

Isn't this exactly what assumeSafeAppend is for?


More information about the Digitalmars-d mailing list