randomIO, std.file, core.stdc.stdio

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 26 11:31:20 PDT 2016


On 7/26/16 1:57 PM, Charles Hixson via Digitalmars-d-learn wrote:

> Thanks.  Since there isn't any excess overhead I guess I'll use stdio.
> Buffering, however, isn't going to help at all since I'm doing
> randomIO.  I know that most of the data the system reads from disk is
> going to end up getting thrown away, since my records will generally be
> smaller than 8K, but there's no help for that.
>

Even for doing random I/O buffering is helpful. It depends on the size 
of your items.

Essentially, to read 10 bytes from a file probably costs the same as 
reading 100,000 bytes from a file. So may as well buffer that in case 
you need it.

Now, C i/o's buffering may not suit your exact needs. So I don't know 
how it will perform. You may want to consider mmap which tells the 
kernel to link pages of memory directly to disk access. Then the kernel 
is doing all the buffering for you. Phobos has support for it, but it's 
pretty minimal from what I can see: http://dlang.org/phobos/std_mmfile.html

-Steve


More information about the Digitalmars-d-learn mailing list