Convert some ints into a byte array without allocations?

Samson Smith via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 16 07:51:11 PST 2016


On Saturday, 16 January 2016 at 15:42:39 UTC, bearophile wrote:
> Yazan D:
>
> On Saturday, 16 January 2016 at 14:42:27 UTC, Yazan D wrote:
>> ubyte[] b = (cast(ubyte*) &a)[0 .. int.sizeof];
>
> Better to use the actual size:
>
> ubyte[] b = (cast(ubyte*) &a)[0 .. a.sizeof];
>
> Bye,
> bearophile

Good thinking, I won't have to change it around if I change the 
type of my co-ords later.

Thanks :)


More information about the Digitalmars-d-learn mailing list