Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - fsetvbuf() set the size of the file i/o buffer http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 fsetvbuf()          Set the size of the file I/O buffer
------------------------------------------------------------------------------
 Declaration
   fileio.hdr

 Syntax
   func logical fsetvbuf extern
   param       file fStream, ;
         value uint uBufferSize

 Arguments
   fStream is the file stream to manipulate.
   uBufferSize is the requested size of the file I/O buffer in bytes.

 Return
   A logical indicating the success of operation.

 Description
   This function allows the modification of the size of a dynamically
   allocated buffer for file I/O (default is 1 Kbyte). Valid sizes range
   from 64 up to 16384 bytes. Each open file stream has its own buffer
   which may be sized separately.

   Increasing the size of a file buffer results in better performance,
   because the number of disk accesses is reduced. On the other hand,
   this decreases the amount of available dynamic memory at runtime.

   After resizing the buffer, file streams opened for read will automatically
   be filled with valid data, file streams opened for write or create will
   automatically be flushed to disk, before the buffer is resized.

   After calling fsetvbuf() it is usually necessary to also call the
   frewind() function to ensure correct file pointer position for
   subsequent file operations.

 Example
   #define EXAMPLE_FILE
   #include example.hdr

   // During a file copy, a larger buffer increase the speed dramatically
   
   proc Test_fsetvbuf
   vardef
      char    cSrc, cDest
      file    fSRc, fDest
      int     iChar
      logical lOK
   enddef
   lOK := .f.
   cSrc  := argv( 1 )
   cDest := argv( 2 )
   if exist( cSrc ) .and. .not. isempty( cDest )
      if fopen( fSrc, cSrc, F_READ, F_BINARY )
         if fopen( fDest, cDest, F_CREATE, F_BINARY )
            lOK := .t.
            fsetvbuf( fSrc, 15000 )
            fsetvbuf( fDest, 15000 )
            do while .not. feof( fSrc )
               iChar := fgetc( fSrc )
               fputc( fDest, iChar )
            enddo
            fclose( fDest )
         endif
         fclose( fSrc )
      endif
   endif
   if lOK
      ? "File copied"
   else
      ? "Usage: test.exe <sourcefile> <destfile>"
   endif
   endproc

   proc main
   Test_fsetvbuf()
   endproc

See Also: fopen() frewind()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson