Transferring files while bypassing the UBC

Mac OSX specific forum
Totusoft
User
User
Posts: 15
Joined: Tue Feb 12, 2013 4:00 pm
Location: Minnesota, USA
Contact:

Transferring files while bypassing the UBC

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Transferring files while bypassing the UBC

Post by wilbert »

What is the UBC ???
fcntl can be imported using ImportC.
Windows (x64)
Raspberry Pi OS (Arm64)
Totusoft
User
User
Posts: 15
Joined: Tue Feb 12, 2013 4:00 pm
Location: Minnesota, USA
Contact:

Re: Transferring files while bypassing the UBC

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3944
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Transferring files while bypassing the UBC

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
Totusoft
User
User
Posts: 15
Joined: Tue Feb 12, 2013 4:00 pm
Location: Minnesota, USA
Contact:

Re: Transferring files while bypassing the UBC

Post 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
Post Reply