1

I have many float data which is generated from an image. I want to store it to a file, like XX.dat ( general in C). and I will read it again to do further processing.

I have method to represent float by nsstring and write it in to .txt file. but it is too slow. Is there some function which is same as fwrite( *data , *pfile) and fread(*buf, *pfile) in c? or some new idea?

many thanks!

2 Answers2

1

In iOS you can still make use of the standard low-level file (and socket, among other things) API's. So you can use fopen(), fwrite(), fread(), etc. just as you would in any other C program.

This question has some examples of using the low-level file API on iOS: iPhone Unzip code

Another option to consider is writing your floats into something like an NSMutableData instance, and then writing that to file. That will be faster than converting everything to strings (you'll get a binary file instead of a text one), though probably still not as fast as using the low-level API's. And you'd probably have to use something like this to convert between floats and byte-arrays.

Community
  • 1
  • 1
aroth
  • 54,026
  • 20
  • 135
  • 176
0

If you are familiar with lower level access, you could mmap your file, and then access the data directly just as you would any allocated memory.

Jody Hagins
  • 27,943
  • 6
  • 58
  • 87