2
votes

I'm looking into storing lots of number as Int16. Considering Core data because the rest of the models are implemented in Core data.

So I did a simple application. Core data with 1 entity and 1 attribute of Int16 type. Inserted 1 million entries in SQLite storage type and the file size turns out to be 16.2MB. Actually if I change to Int64, I would get the same file size. If writing simple binary C array, should be around 2MB.

So question is, why did Core data bother with so many different kind of number format if everything will be casted to NSNumber anyway? And is there any way to make Core data store the data as true Int16? or short in C terms?

Thanks.

1
Bear in mind Core Data is storing more than just the raw numbers. It needs to maintain the rest of the database structure around them.Mike Abdullah

1 Answers

3
votes

Just because Core Data supports all those number formats doesn’t mean the underlying storage engine has to store them in a different way. If you tried using the binary store you’d probably get different file sizes.

For storing that many integers I would put them all in a NSData object and store this in Core Data.