Passing dynamic arrays
Jonathan M Davis
jmdavisProg at gmx.com
Mon Nov 8 17:43:17 PST 2010
On Monday, November 08, 2010 16:50:46 so wrote:
> D arrays very powerful but you first need to understand what is going on.
> You should check the book.
> An inconsistency is the copy of static arrays at assignment, but necessary
> one.
> One thing i don't like about D arrays is an undefined case in dynamic
> array reallocation.
It's perfectly defined, just not knowable at compile time. You can even check the
array's capacity if you want to try and figure out when it's going to happen.
And there's not really any reasonable alternative. What would have happen
instead? Make an array reallocate _every_ time that it's resized? That would be
highly inefficient and could really degrade performance. Appending becomes O(n)
instead of amortized O(1). If you're not altering the actual elements of the
array, then the current implementation is great. If you _are_ altering them,
then simply dup the array to guarantee that it's been reallocated.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list