tags:

views:

74

answers:

4

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?

+1  A: 

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.

Frank Shearar
+2  A: 

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).

Stephen
+1  A: 

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.

Chris Thornton
+1  A: 

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.)

KennyTM