dontWatchMyProfile
dontWatchMyProfile

Reputation: 46300

Does "opening a file" mean loading it completely into memory?

There's an AudioFileOpenURL function which opens an file. With AudioFileReadPackets that file is accessed to read packets. But one thing that stucks in my brain is: Does AudioFileOpenURL actually load the whole monster into memory? Or is that a lightweight operation?

So is it possible to read data from a file, only a specific portion, without having the whole terabytes of stuff in memory?

Upvotes: 2

Views: 1590

Answers (4)

kennytm
kennytm

Reputation: 523184

AudioFileOpenURL will open(2) the file and read the necessary info (4096 bytes) to determine the audio type.

open(2) won't load the whole file into RAM.

(AudioFileOpenURL is a C API, not Objective-C.)

Upvotes: 1

Chris Thornton
Chris Thornton

Reputation: 15817

I don't know about objective-c, but with most languages you open the file, and that just gives you the ability to THEN access the contents with a READ operation. In your case, you can perform a SEEK to move the file pointer to the desired location, then read the number of bytes you need.

Upvotes: 2

Stephen
Stephen

Reputation: 49156

Does AudioFileOpenURL actually load the whole monster into memory?

No, it just gets you a file pointer.

Or is that a lightweight operation?

Yep, fairly lightweight. Just requires a filesystem lookup.

So is it possible to read data from a file, only a specific portion, without having the whole terabytes of stuff in memory?

Yes, you can use fseek to go a certain point in the file, then fread to read it into a buffer (or AudioFileReadBytes).

Upvotes: 3

Frank Shearar
Frank Shearar

Reputation: 17132

No, it doesn't load the entire file into memory. "Opens a file" returns a handle to you allowing you to read from or write to a file.

Upvotes: 1

Related Questions