Reading bytes and converting to int

Tommi tommitissari at hotmail.com
Sun Aug 26 07:19:14 PDT 2012


On Saturday, 25 August 2012 at 20:58:47 UTC, Jonathan M Davis 
wrote:
> auto buf = file.rawRead(new ubyte[](4));

Could we somehow skip making the temporary buffer, and read from 
the file directly into an existing variable. Can we make a slice 
of one element that points to an existing value.

import std.stdio;

struct BigValue // has no indirection
{
     int  m_value1;
     int  m_value2;
     long m_value3;
     // ...
}

BigValue g_bigValue;

void fun()
{
     auto file = File("filename");

     // How to create a slice of size 1 which references 
g_bigValue?
     BigValue[] refToBigValue /* = ? */ ;

     buffer = file.rawRead(refToBigValue);
}


More information about the Digitalmars-d-learn mailing list