I am trying to figure out the best way to do some file transfers while bypassing the UBC. I cannot find a way to do this with Purebasic built in commands or Cocoa, but am learning that it can be done using fcntl.h included with XCode. Is fcntl.h something that can be used in Purebasic (ie, ImportC) or am I way off base?
Thanks,
-Pete
Transferring files while bypassing the UBC
Re: Transferring files while bypassing the UBC
What is the UBC ???
fcntl can be imported using ImportC.
fcntl can be imported using ImportC.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Transferring files while bypassing the UBC
Thanks for your response Wilbert. The UBC is the Unified Buffer Cache. All file transfers (local, USB, etc.) goes through this on the Mac. For instance, if you copy a file to a USB drive, it may take many seconds to minutes. If you read it back again, it takes less than a second because it's cached in the UBC. I want to bypass the UBC so that I can get accurate write and read speeds. Creating a file with Purebasic's #PB_File_NoBuffering flag does not bypass the UBC.
How do I use this in ImportC? Something like ImportC "fcntl.h" and then define my fcntl statement?
-Pete
How do I use this in ImportC? Something like ImportC "fcntl.h" and then define my fcntl statement?
-Pete
Re: Transferring files while bypassing the UBC
You can import fcntl but you can also use it directly using an underscore.
Code: Select all
#F_GLOBAL_NOCACHE = 55
FileName.s = "CacheTest.dat"
*MemoryBuffer = AllocateMemory(1048576)
RandomData(*MemoryBuffer, 1048576)
CreateFile(0, FileName)
WriteData(0, *MemoryBuffer, 1048576)
CloseFile(0)
fh = CocoaMessage(0, 0, "NSFileHandle fileHandleForUpdatingAtPath:$", @"CacheTest.dat")
If fh
fcntl_(CocoaMessage(0, fh, "fileDescriptor"), #F_GLOBAL_NOCACHE, 1)
CocoaMessage(0, fh, "closeFile")
EndIfWindows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: Transferring files while bypassing the UBC
Thanks Wilbert. Your example helped a lot! I worked it into my routine and testing is exactly what I was hoping to be able to do.
-Pete
-Pete

