Setting array length to 0 discards reserved allocation?

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 19 17:13:23 PDT 2014


On Tue, 19 Aug 2014 23:58:57 +0000
Andrew Godfrey via Digitalmars-d <digitalmars-d at puremagic.com> wrote:

> In either case, we are "passing a reference by value".
yes. but passing null class will not allow to call it's methods, and
passing null array will. i.e.

  auto foo (MyClass a) { return a.length; }

will crash if length is not a static method (and it can't be static)
and foo is called like this: foo(null). but the same call will work for
'int[]'.

so user can assume that 'int[]' is something similar to class, and it's
perfectly ok to use int[] methods, and '~=' is just the overloaded
method, which should change contents of passed dynarray. again,
overloaded '~=' will work for class (more or less), but will
inevitably fail (i.e. will not change passed arg) for dynarray.

and it's clear that 'a = new MyClass()' creates new object. and it's
not clear at all that 'a ~= 42' creates new object too. it's
counterintuitive.

that's why i think that we need new term.
-------------- 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/20140820/7e6973d4/attachment.sig>


More information about the Digitalmars-d mailing list