On Friday, 24 February 2017 at 07:38:04 UTC, Mike Parker wrote:
On Friday, 24 February 2017 at 04:22:17 UTC, Jonathan Marler
wrote:
I discovered the .capacity property of arrays. I don't know
why I've never seen this but it looks like this is how readln
is recovering this seemingly lost peice of data. This does
have an odd consequence though, if you pass a slice into
readln it will read past the end of it if the underlying
buffer is larger. This might be something worth adding to the
documentation.
Also I'm not completely sure how .capacity works, I assume it
has to look up this information in the memory management
metadata. Any enlightenment on this subject is appreciated.
It also says it's a O(log(n)) operation so I'm guessing it's
looking it up in some sort of binary tree data structure.
https://dlang.org/phobos/object.html#.capacity
And although it never mentions capacity directly (capacity may
not have been available when it was written, I can't recall), the
How It Works section of Steven's array article gives the gist of
it.
https://dlang.org/d-array-article.html