The MASM Forum

General => The Workshop => Topic started by: sinsi on March 11, 2013, 01:37:16 PM

Title: Best size for I/O buffer
Post by: sinsi on March 11, 2013, 01:37:16 PM
I have my disc imaging program working OK, just wondering what would be the best buffer size for reading a CD/DVD.
I am opening a volume, using "\\.\D:", should I use FILE_FLAG_SEQUENTIAL_SCAN? Not sure if they work on discs.
Title: Re: Best size for I/O buffer
Post by: hutch-- on March 11, 2013, 01:50:08 PM
sinsi,

usually the seek time on a CD is reasonably slow alongside a hard disk so I would be inclined to use a very large IO buffer but be willing to try different sizes to see what works best. It has a lot to do with the internals of the API you want to use as to whether it uses an internal buffer of a limited size like 8 or 16k. If so a small buffer would probably work best but I would time it as there may not be much documentation on how the API internals work.
Title: Re: Best size for I/O buffer
Post by: dedndave on March 11, 2013, 01:56:31 PM
if i remember, CD's are divided into 2 kb chunks (you may want to check that - lol)
the disk cluster may be 8 kb, 16 kb, and so on
so, some multiple of the disk cluster would seem logical

http://support.microsoft.com/kb/98756 (http://support.microsoft.com/kb/98756)
Title: Re: Best size for I/O buffer
Post by: sinsi on March 11, 2013, 02:27:09 PM
Using a 2KB buffer took 5 minutes to copy 650MB, a 1MB buffer took 3 minutes.
I might rewrite it in 64-bit and use a buffer the size of the disc, see how that goes.
Title: Re: Best size for I/O buffer
Post by: dedndave on March 11, 2013, 02:50:53 PM
you may want to write it so you can try several buffer sizes   :P
of course, it could do the first several buffer read.writes with different buffer sizes
then, select the one that was fastest for the rest of the copy process
Title: Re: Best size for I/O buffer
Post by: Magnum on March 12, 2013, 12:11:25 AM
Three minutes is pretty fast for making a CD.

Andy
Title: Re: Best size for I/O buffer
Post by: sinsi on March 12, 2013, 02:41:17 PM
No real difference between loading the whole disc and using a 1MB buffer, both around 3 minutes.
Really, not much difference between 64KB and 1MB.
Using a buffer also allows for user feedback without all the trouble of overlapped I/O.

Andy, it's not burning a CD, just reading it to a .iso file.
Good for use with VMs and now with Windows 8 - you just mount the disc as a drive.
It's a better way of backing up a disc too, no more scratches.
Title: Re: Best size for I/O buffer
Post by: Tedd on March 13, 2013, 02:21:17 AM
I find a 4MB buffer usually works quite well for straight copying, though I haven't tried it with a CD/DVD.
FILE_FLAG_SEQUENTIAL_SCAN is a caching hint, so it won't have a huge effect in this case, but it won't hurt either.

The CD drive has its own internal buffer, so your aim is really to ensure that can be emptied and refilled as quickly as possible; once that's satisfactory, increasing your buffer size further will probably have little effect.
Of course, the best way to find out is to test various sizes with different settings - find the size of the CD drive buffer, and then try 1/2, 1, 2, 4 as multiples  ;)