struct to byte[]

BCS fromnowhere at pathlink.com
Thu Dec 14 10:10:56 PST 2006


== Quote from Derek Parnell (derek at nomail.afraid.org)'s article
> With this, the '&t' phrase takes the address of the data as
> passed-by-value. [...] So you end up with a ubyte[]
> array that references a copy of the struct/data you supplied
> [...] Of course, that might be what you are trying to do ;-)

I get it now! The kind of things I would use it for would only care about the copy
from a performace standpoint.

OTOH: would this work?

ubyte [] toByteArray (T) (inout T t)
{
   return (cast(ubyte *)&t)[0..T.sizeof].dup
}



More information about the Digitalmars-d mailing list