Page 1 of 1
Transferring files while bypassing the UBC
Posted: Tue Jul 02, 2013 3:23 pm
by Totusoft
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
Re: Transferring files while bypassing the UBC
Posted: Tue Jul 02, 2013 4:12 pm
by wilbert
What is the UBC ???
fcntl can be imported using ImportC.
Re: Transferring files while bypassing the UBC
Posted: Tue Jul 02, 2013 4:58 pm
by Totusoft
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
Re: Transferring files while bypassing the UBC
Posted: Tue Jul 02, 2013 5:37 pm
by wilbert
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")
EndIf
Re: Transferring files while bypassing the UBC
Posted: Wed Jul 03, 2013 3:08 am
by Totusoft
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