Setting array length to 0 discards reserved allocation?

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 17 00:32:51 PDT 2014


On Thu, 14 Aug 2014 06:46:40 +0000
Andrew Godfrey via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

sorry for the late answer.

> Don't think I'm being flippant, but I have trouble interpreting 
> such feedback, because D's dynamic array semantics ARE 
> complicated.
and it will be even more complicated if we will rename 'em to 'array
references'.

i completely agree that D dynarray docs can be made clearer and i
appreciate any efforts which makes docs better. i'm just against
'reference' term -- seems that i'm from that minority that becomes
immediately confused when reading 'array reference'. what i expect from
'reference' is that this code works:

  void foo (int[] a) {
    a ~= 42;
  }
  ...
  int[] arr;
  arr ~= 666;
  foo(arr);
  assert(arr.length == 1 && arr[0] == 42);

but it doesn't. so arrays clearly aren't 'references' (as 'reference',
to my opinion, should keep 'pass by reference' semantics in this case).

so maybe we should coin some new word to describe dynarrays in D.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140817/eae8d417/attachment.sig>


More information about the Digitalmars-d mailing list