Setting array length to 0 discards reserved allocation?

Andrew Godfrey via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 25 08:07:53 PDT 2014


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?

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.

(As I understand it from the article, the problem is that
reducing 'length' also reduces 'used', whereas in this case
I really want that slice to continue to own the entire reserved 
amount.)


More information about the Digitalmars-d mailing list