On Monday, 19 November 2018 at 22:14:25 UTC, Neia Neutuladh wrote:

Nothing stops you from writing:

    SomeStruct myStruct;
    fd.rawRead((cast(ubyte*)&myStruct)[0..SomeStruct.sizeof]);

Standard caveats about byte order and alignment.

Never would I thought about casting struct to static array. If I understood correctly you cast myStruct pointer to ubyte pointer and then construct static array on stack with tmpArray.ptr = (ubyte pointer) and tmpArray.sizeof = SomeStruct.sizeof

What I figured out when I woke up is that I never needed c style arrays. What I could do is to allocate enough data for all file in ubyte array and just use slices to read data by chunks and cast them into necessary structs.

Thanks Neia Neutuladh and H. S. Teoh for giving me some pointers
https://www.explainxkcd.com/wiki/index.php/138:_Pointers

Reply via email to