How to dynamically alias a struct to a byte array?

Ali Çehreli acehreli at yahoo.com
Sun Feb 17 21:32:43 PST 2013


On 02/17/2013 12:12 PM, jerro wrote:

 > You don't need to cast it each time, you can do something like:
 >
 > auto structPointer = cast(MyStruct*) byteArray.ptr;

And that pointer can be converted to a D slice:

   MyStruct[] slice = structPointer[0..number_of_struct_objects];

Use 'slice' as a regular D slice from that point on.

Ali



More information about the Digitalmars-d-learn mailing list