Setting array length to 0 discards reserved allocation?

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 25 08:54:08 PDT 2014


On Fri, Jul 25, 2014 at 03:07:53PM +0000, Andrew Godfrey via Digitalmars-d wrote:
> On Friday, 25 July 2014 at 04:38:40 UTC, Jonathan M Davis via Digitalmars-d
> wrote:
> >You really should read this article:
> >
> >http://dlang.org/d-array-article.html
> 
> Thank you, that was educational.
> What I needed to read was that "A slice does not own the array, it
> references the array." - which I knew, but I hadn't internalized that
> even when a dynamic array is a private member, it is accessed via a
> slice and the runtime is not aware when there's a 1-to-1
> correspondence between the two.
> 
> The documentation could help a bit more. I'm game to
> try to make a pull request for this, but I'm wondering
> if the library docs can actually point to the article?

That's a very good idea. I think that would dispel a lot of
misconceptions that newcomers might have.


> More feasibly, I'm thinking:
> Both the documentation for length() (http://dlang.org/arrays)
> and reserve() (http://dlang.org/phobos/std_array.html)
> should at least mention assumeSafeAppend.
> An example similar to what I posted may also be worthwhile.
[...]

Yes, please submit a PR for this.


T

-- 
I see that you JS got Bach.


More information about the Digitalmars-d mailing list