c++ - Programmer thought process: determining a maximum number of bytes to read when using ReadFile with the Windows API -


i need call readfile function of windows api:

bool winapi readfile(   _in_        handle       hfile,   _out_       lpvoid       lpbuffer,   _in_        dword        nnumberofbytestoread,   _out_opt_   lpdword      lpnumberofbytesread,   _inout_opt_ lpoverlapped lpoverlapped ); 

the argument i'm interested in 3rd one:

nnumberofbytestoread [in]

the maximum number of bytes read.

i'm not interested in "magic number" put there process seasoned programmer takes determine number put there, preferably in numbered steps.

also keep in mind writing program in assembler i'm more interested in thought process perspective.


this requires plenty of insight both windows , hardware. but, in general, here possible directions:

  • is write buffered or unbuffered? if unbuffered, may not able choose size, have follow strict rules both size , alignment of buffer.
  • in general, you'd want let operating system handle of work possible, because knows lot more storage device , various users in userspace. might want fetch whole thing @ once, if possible (see points below).
  • if turns out that isn't enough, may try outsmart playing around various sizes, account cases might able use current buffers os, reason, wouldn't make use of different requests.
  • otherwise, might play around sizes ranging anywhere between disk sector size , multiples of page size, these cached somewhere, , map directly actual hardware requests.
  • other performance, there's question of how can afford store in process's memory @ given time.
  • there's question of sending large requests might block other processes getting chance in there , data in between—if os doesn't take care of somehow.
  • there's possibility requesting too-large chunks os might defer request till other processes humble ones served. on flip side, if it's intersecting addresses, might serve yours first in order serve other ones cache.

in general, you'd want play around until works enough.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -