Reading bytes and converting to int

Timon Gehr timon.gehr at gmx.ch
Sun Aug 26 08:18:25 PDT 2012


On 08/26/2012 04:19 PM, Tommi wrote:
> 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 /* = ? */ ;

auto refToBigValue = (&g_bigValue)[0..1];

>
>      buffer = file.rawRead(refToBigValue);
> }



More information about the Digitalmars-d-learn mailing list