Don't use arrays as stacks

2011-09-24 Thread Nick Sabalausky
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

Re: Don't use arrays as stacks

2011-09-24 Thread Jonathan M Davis
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 he

Re: Don't use arrays as stacks

2011-09-25 Thread Andrei Alexandrescu
On 9/25/11 1:37 AM, 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. Th

Re: Don't use arrays as stacks

2011-09-25 Thread Nick Sabalausky
"Nick Sabalausky" wrote in message news:j5mi7l$1dtf$1...@digitalmars.com... > 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

Re: Don't use arrays as stacks

2011-09-25 Thread Andrew Wiley
On Sun, Sep 25, 2011 at 1:45 AM, Jonathan M Davis 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 f

Re: Don't use arrays as stacks

2011-09-25 Thread Jonathan M Davis
On Sunday, September 25, 2011 03:18:29 Andrew Wiley wrote: > On Sun, Sep 25, 2011 at 1:45 AM, Jonathan M Davis 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 i

Re: Don't use arrays as stacks

2011-09-25 Thread Nick Sabalausky
"Jonathan M Davis" wrote in message news:mailman.160.1316939358.26225.digitalmar...@puremagic.com... > On Sunday, September 25, 2011 03:18:29 Andrew Wiley wrote: >> >> Isn't this exactly what assumeSafeAppend is for? Hmm, I didn't know about that. (Actually, I remember hearing it mentioned befo

Re: Don't use arrays as stacks

2011-09-25 Thread Jonathan M Davis
On Sunday, September 25, 2011 07:05:34 Nick Sabalausky wrote: > "Jonathan M Davis" wrote in message > news:mailman.160.1316939358.26225.digitalmar...@puremagic.com... > > > On Sunday, September 25, 2011 03:18:29 Andrew Wiley wrote: > >> Isn't this exactly what assumeSafeAppend is for? > > Hmm, I

Re: Don't use arrays as stacks

2011-09-25 Thread bearophile
Nick Sabalausky: > https://www.semitwist.com/articles/article/view/don-t-use-arrays-as-stacks Is it possible to write a function like: ForeachType!A unsafePop(A)(A)if(isDynamicArray!A) { /*...*/ } that contains both the popping (and something like assumeSafeAppend to mess with the druntime dat

Re: Don't use arrays as stacks

2011-09-25 Thread Lutger Blijdestijn
Nick Sabalausky wrote: > "Jonathan M Davis" wrote in message > news:mailman.160.1316939358.26225.digitalmar...@puremagic.com... >> On Sunday, September 25, 2011 03:18:29 Andrew Wiley wrote: >>> >>> Isn't this exactly what assumeSafeAppend is for? > > Hmm, I didn't know about that. (Actually, I r

Re: Don't use arrays as stacks

2011-09-26 Thread Steven Schveighoffer
On Sun, 25 Sep 2011 02:37:25 -0400, 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 help

Re: Don't use arrays as stacks

2011-09-26 Thread Steven Schveighoffer
On Sun, 25 Sep 2011 07:05:34 -0400, Nick Sabalausky wrote: "Jonathan M Davis" wrote in message news:mailman.160.1316939358.26225.digitalmar...@puremagic.com... On Sunday, September 25, 2011 03:18:29 Andrew Wiley wrote: Isn't this exactly what assumeSafeAppend is for? Hmm, I didn't know ab

Re: Don't use arrays as stacks

2011-09-26 Thread Nick Sabalausky
"Steven Schveighoffer" wrote in message news:op.v2e19fkieav7ka@localhost.localdomain... > On Sun, 25 Sep 2011 02:37:25 -0400, 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

Re: Don't use arrays as stacks

2011-09-26 Thread bearophile
Nick Sabalausky: > Not that slicing a stack would be all that common, but if it were done for > whatever reason... Is it possible to write a function like: ForeachType!A unsafePop(A)(A)if(isDynamicArray!A) { /*...*/ } that contains both the popping (and something like assumeSafeAppend to mess

Re: Don't use arrays as stacks

2011-09-26 Thread Nick Sabalausky
"bearophile" wrote in message news:j5rn5o$1q0g$1...@digitalmars.com... > Nick Sabalausky: > >> Not that slicing a stack would be all that common, but if it were done >> for >> whatever reason... > > Is it possible to write a function like: > > ForeachType!A unsafePop(A)(A)if(isDynamicArray!A) {

Re: Don't use arrays as stacks

2011-09-28 Thread Steven Schveighoffer
On Tue, 27 Sep 2011 00:22:02 -0400, Nick Sabalausky wrote: "Steven Schveighoffer" wrote in message [1] Why is the capacity set to zero instead of the actual length of four? I'm not certain, but my guess is that zeroing the value is slightly faster than copying the length. Either that, or perh

Re: Don't use arrays as stacks

2011-09-28 Thread Nick Sabalausky
"Steven Schveighoffer" wrote in message news:op.v2ita9hseav7ka@localhost.localdomain... > On Tue, 27 Sep 2011 00:22:02 -0400, Nick Sabalausky wrote: > > There's never a guarantee that a slice will always point at the current > values. There can't be, because you can never guarantee it will not

Re: Don't use arrays as stacks

2011-09-28 Thread Steven Schveighoffer
On Wed, 28 Sep 2011 12:11:29 -0400, Nick Sabalausky wrote: Of course, as it is now, the slice owner won't even know if the values it points to have been pooped off and *not* been pushed back on again. Freudian slip or simple typo? Either way, *hilarious* :) Gives a new mental picture

Re: Don't use arrays as stacks

2011-09-28 Thread Nick Sabalausky
"Steven Schveighoffer" wrote in message news:op.v2i2yv0beav7ka@localhost.localdomain... > On Wed, 28 Sep 2011 12:11:29 -0400, Nick Sabalausky wrote: > >> Of course, as it is now, the slice owner won't even know if >> the values it points to have been pooped off and *not* been pushed back >> on

Re: Don't use arrays as stacks

2011-09-28 Thread Nick Sabalausky
"Nick Sabalausky" wrote in message news:j5vte2$3ql$1...@digitalmars.com... > > ...Although I'm not [*sure*] I like the implications... >