Using C's fread/fwrite with File objects

pineapple via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 22 11:58:40 PDT 2015


On Thursday, 22 October 2015 at 18:28:50 UTC, Ali Çehreli wrote:
> If you already have a piece of memory, it is trivial to convert 
> it to a slice in D:
>
>   auto slice = existing_pointer[0 .. number_of_elements];
>
>
> http://ddili.org/ders/d.en/pointers.html#ix_pointers.slice%20from%20pointer
>
> The operation is not expensive because D slices are nothing but 
> a pointer and length.
>
> Ali

Cool, I hadn't realized slices worked like that. Still, it was 
more convenient to use fread and fwrite in this case. I had an 
pointer where I wanted to be able to read and write one byte at a 
time and fread/fwrite are familiar and comfortable options to me.


More information about the Digitalmars-d-learn mailing list