FIFO stack

Nick Sabalausky a at a.a
Thu Oct 27 13:57:56 PDT 2011


"Ary Manzana" <ary at esperanto.org.ar> wrote in message 
news:j8buhd$1s80$1 at digitalmars.com...
> On 10/27/11 8:38 AM, Nick Sabalausky wrote:
>> "Ary Manzana"<ary at esperanto.org.ar>  wrote in message
>> news:j89gle$9nn$1 at digitalmars.com...
>>> On 10/26/11 1:28 PM, Jonathan M Davis wrote:
>>>> On Wednesday, October 26, 2011 09:00 Dominic Jones wrote:
>>>>>> Also an plain array is a good stack. :)
>>>>>
>>>>> I'd rather not use a plain array because (I assume) that when I push
>>>>> or pop using arrays, a swap array is created to resize the original.
>>>>> If this is not the case, then an array will certainly do.
>>>>> -Dominic
>>>>
>>>> Not exactly. If you want to know more about how arrays work, you should
>>>> read
>>>> this: http://www.dsource.org/projects/dcollections/wiki/ArrayArticle 
>>>> It's
>>>> a
>>>> great read. As for using an array as a stack, you can do it with a
>>>> wrapper
>>>> struct, but using it by itself would result in a lot more reallocations
>>>> than
>>>> you'd want, as discussed here:
>>>> https://www.semitwist.com/articles/article/view/don-t-use-arrays-as-stacks
>>>>
>>>> - Jonathan M Davis
>>>
>>> I think that if you have to read an article that long, with all the
>>> explanations of the different caveats a programmer can bump to when 
>>> using
>>> them, to understand how arrays and slices work.... something must be
>>> wrong.
>>>
>>> Things should be simpler.
>>
>> FWIW, my article can be summarized with a line that's [poorly] located 
>> right
>> around the middle (annotations added):
>>
>> "Slicing an array is fast [no allocation or copying], and appending is
>> usually fast  [usually no allocation or copying], but slicing the end off
>> and then appending is slow [does an allocate and copy]."
>>
>> I guess I have a habit of making things longer than they need to be ;)
>
> Nah, I liked your article, it assumes I know nothing and I like that. 
> Maybe I did was exaggerating...
>

Thanks. But you did have a good point, in fact it had already been nagging 
at me a little bit anyway: There's a very simple summary of the matter, but 
I didn't get around to spitting it out until halfway through. I've added a 
little thing to the top and feel a lot better about it now.





More information about the Digitalmars-d-learn mailing list