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:46:00 PST 2016


On Saturday, 16 January 2016 at 14:42:27 UTC, Yazan D wrote:
> On Sat, 16 Jan 2016 14:34:54 +0000, Samson Smith wrote:
>
>> [...]
>
> You can do this:
> ubyte[] b = (cast(ubyte*) &a)[0 .. int.sizeof];
>
> It is casting the pointer to `a` to a ubyte (or byte) pointer 
> and then taking a slice the size of int.

This seems to work. Thankyou!


More information about the Digitalmars-d-learn mailing list