Author Topic: Flush File Buffers  (Read 162 times)

Offline moises1953

  • Newbie
  • Posts: 38
Flush File Buffers
« on: August 01, 2020, 02:59:00 AM »
Windows has a FlushFileBuffers function to move the pending data from cache to file, without closing the file:
I'm interested in implement this function but need the windows file handle, and FILEATTR has not been implemented.
There is any way to perform fileflushing?.
Posible to add a _FILEFLUSH statement (or similary) to QB64?

Offline doppler

  • Forum Regular
  • Posts: 109
Re: Flush File Buffers
« Reply #1 on: August 01, 2020, 07:13:06 PM »
The only reason windows has the flush function is to accelerate closing and flushing files.  Normally windows will flush at idol times or when a threshold is meet.  The only reason I have had to use a flush function program is when I can't remove a external drive (eject/unmount).  Such as when I can not remove a flash drive because some program is using it. (none really are).  External devices are the last to get flushed.  Hence it seems slow.

As far as QB64 needing it.  QB64 is not fast enough to reach windows threshold.  And any records written out but not flushed are in memory cached.  Quick re-access.  Close and reopen a file will commit a flush faster.  So just use close and reopen.

PS. Beside you can always use a dos shell to execute a flush. (call your program)
« Last Edit: August 01, 2020, 07:15:50 PM by doppler »

Offline moises1953

  • Newbie
  • Posts: 38
Re: Flush File Buffers
« Reply #2 on: Yesterday at 02:37:37 AM »
Thank's doppler for your help.
The implementation of FILEATTR may solve the problem:
handle=FILEATTR(fileno, 2)

Offline Dav

  • Forum Regular
  • Posts: 232
Re: Flush File Buffers
« Reply #3 on: Yesterday at 08:45:18 AM »
I was wondering...would doing a SEEK to EOF make the file system flush first before seeking?

- Dav 

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2209
  • LET IT = BE
Re: Flush File Buffers
« Reply #4 on: Yesterday at 10:04:21 AM »
You could just CLOSE the file handle and then OPEN it again - I believe the flushing would occur immediately.

Offline Petr

  • Forum Resident
  • Posts: 1349
  • The best code is the DNA of the hops.
Re: Flush File Buffers
« Reply #5 on: Yesterday at 10:30:33 AM »
I may not have understood the problem right at the beginning of the thread, but:

If you are in the file opened as record number 1 in the mode for binary access and you are in the position, say, byte 150 in the file, then you get the rest of the file as GET 1, LOF (1) - SEEK (1), REC $ where REC $ is fixed a string of length LOF (1) - SEEK (1).

I think it can be solved, it just depends on the way you open the file. I assume that QB64 is fast enough for that (when I write about 1 gigabyte with QB64 to disk in a very short time). When you open a file in a new block of memory (MEMNEW), you gain direct access to the data in memory and you have directly accessible your own cache equivalent.