I feel the dynamic array .sizeof property is kind of a bait and switch
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 25 19:32:07 PDT 2017
On Wednesday, 26 July 2017 at 02:24:06 UTC, WhatMeForget wrote:
> Static Arrays have property
> .sizeof which returns the array length multiplied by the number
> of bytes per array element.
>
> Dynamic Arrays have property
> .sizeof which returns the size of the dynamic array reference,
> which is 8 in 32-bit builds and 16 on 64-bit builds.
Both actually already do exactly the same thing: .sizeof returns
the size of the variable. Same thing with pointers, class
references, and everything else.
> I've hand rolled a function which is working for me currently,
> but with my coding ability, I'd feel much safer with something
> official :)
You could also do (cast(ubyte[]) array).length.
> It just seems like something this basic regarding dynamic
> arrays should just be built-in.
What are you using it for?
More information about the Digitalmars-d-learn
mailing list