I am a seasoned PowerBASIC user but am interested in PureBASIC, mainly because I will soon need to port some of my existing PowerBASIC applications to Linux.
My applications typically involve processing large disk files (often as large as 1TiB). To optimise speed (disk accesses being the most significant bottleneck) my normal approach is to allocate as much memory as possible and then load chunks of the file into memory for processing.
Using PowerBASIC I am able to comfortably allocate a 1GiB (1073741824 byte) buffer on my Windows XP 32-bit box. However using PureBASIC (I am currently using the demo version of the Windows 32-bit compiler) the memory allocation fails. It does allow me to allocate 500MiB (536870912 bytes) however.
Here is the PureBASIC code:-
Code: Select all
EnableExplicit
Define FileName.s, FileHandle.l, FileSize.q, BytesRead.q, *MemoryID
FileName = OpenFileRequester("Select a file","","Binary (.bin)|*.bin|All files (*.*)|*.*",0)
If FileName<>""
FileHandle=ReadFile(#PB_Any,FileName)
If FileHandle
FileSize=Lof(FileHandle)
Debug "File size: "+Str(FileSize)+" bytes."
*MemoryID=AllocateMemory(FileSize,#PB_Memory_NoClear)
If *MemoryID
Debug "Allocated: "+Str(MemorySize(*MemoryID))+" bytes."
BytesRead = ReadData(FileHandle, *MemoryID, FileSize)
Debug "Number of bytes read: " + Str(BytesRead)
Else
Debug "Failed to allocate memory."
EndIf
CloseFile(FileHandle)
If *MemoryID
FreeMemory(*MemoryID)
Debug "Memory freed."
EndIf
Else
Debug "Could not open or read from selected file."
EndIf
Else
Debug "No file selected."
EndIf
Thanks
Robin



