Using C's fread/fwrite with File objects
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Oct 22 11:28:50 PDT 2015
On 10/22/2015 11:20 AM, pineapple wrote:
> I'd like to use fread and fwrite in place of File.rawRead and
> File.rawWrite which force the creation of an array where I'd rather
> specify a buffer location and length.
Would you not create that buffer? :)
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
More information about the Digitalmars-d-learn
mailing list