Click or drag to resize

FFlush Function (IntPtr)

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

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.4a
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. Calling the method with 2 parameters and a second parameter with the value TRUE will significantly slow down your apps! The with 1 parameter works the same as calling FFlush() with a value of FALSE for the second parameter.
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#
1ptrHandle := FOpen2("docs.txt", ;
2        FO_READWRITE + FO_SHARED)
3IF ptrHandle != F_ERROR
4    FWrite(ptrHandle, Space(100))    
5    nKey := Inkey(50)
6    FFlush(ptrHandle)            // Save data
7ENDIF
See Also