Click or drag to resize

FFlush Function

Flush to disk a file opened with a low-level file function.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.2a
Syntax
 FUNCTION FFlush(
	ptrHandle AS IntPtr
) AS LOGIC
View Source

Parameters

ptrHandle
Type: IntPtr
The handle of the open file you want to flush.

Return Value

Type: Boolean
Remarks
FFlush() writes buffers to disk, thus releasing the memory used by those buffers.  If files are being shared in a multi-user or multi-tasking environment, FFlush() allows each user to see the latest contents of the file.  By flushing data from memory, FFlush() can also protect against possible data loss due to a system crash.
Remarks
Tip Tip
The low level File IO functions in the X# runtime are using .Net filestreams in the background.
That means that the file handles returned by FOpen() and FCreate() are not 'normal' file handles, but unique identifiers that are used to find the underlying stream object in a collection of streams in the runtime.
That also means that you can't use file handles for functions such as FRead() and FWrite() that were not created in the X# runtime.
If you want to access the underlying FileStream, then you should call the function FGetStream()
Examples
This example uses FFlush() to flush data automatically after waiting for a key press:
X#
ptrHandle := FOpen2("docs.txt", ;
                FO_READWRITE + FO_SHARED)
IF ptrHandle != F_ERROR
        FWrite(ptrHandle, Space(100))        
        nKey := Inkey(50)
        FFlush(ptrHandle)                        // Save data
ENDIF
See Also