On Thursday, 17 October 2013 at 22:30:52 UTC, Jonathan M Davis wrote:
http://dlang.org/d-array-article.html

It should be enlightening.

Yes, now I understand this article, but only after I had this long discussion here. The relevant statement for me is "The responsible party for managing a dynamic array's memory is the D runtime." For me this means that the programmer isn't suppose to manage allocation and reallocation of the array, because it is abstracted by the slices. Well, if it's so, then I have doubts that it will help to write performant code, BECAUSE of the abstraction.

With this in mind I take back everything I said about slices and leave only a doubt that slices are performant.

---
To clarify previous things:

Whether the concatenation "~=" appends without or with reallocation, depends on the available capacity of the left slice. The concatenation "~" never reallocates and creates always a new slice with capacity of 0.

My prevoius example of the function "removeElement(ref int[], int)" will not work. The right implementation would be:
void removeElement(ref int[] arr, int index) {
  arr[index..$-1] = arr[index+1..$].dup;
  arr.length--;
  arr.assumeSafeAppend();
}

Reply via email to