Best way to store a large array of boolean variables?

I am working on code that requires me to store 60 * 4 boolean values, the names of these values ​​are stored in plist. I need to manipulate boolean values ​​at runtime and could not find a way to update the plist file easily. Also, using the sqlite database to store boolean values ​​becomes fuss for such a large amount of data ... Is there any simple way that I can store and retrieve these values ​​easily both at runtime and after launching the application?

+4
source share
3 answers

I do not want to be a heretic, but there is a simple rule for such cases: premature optimization is the root of all evil.

60 * 4 - a total of 240 Booleans. Even if you somehow manage to save them in the worst way and take 1k for a boolean, it is still only 240k. As long as it is memory, not RAM, who needs it? Why not start with the easiest way and fix it when something comes to you later? SQLite is great for this.

If you are close to delivery and have identified this as a problem, be sure to ignore this answer. :)

+7
source

While it will be much easier to use NSArray or NSMutableArray, as mentioned above, you can look at using the standard C ++ vector class. AFAIK is very economical. memory allocation.

+2
source

You can use the NSData method to store the logical array, but you can also just let cocoa do this naturally:

NSArray* arrayOfBools; // array of 240 NSNumbers, each made with [NSNumber numberWithBool:NO]; 

then

 [[NSUserDefaults standardUserDefaults] setObject:arrayOfBools forKey:@"MyNameForThe240"]; 

Extract them:

 NSArray* savedBools = [[[NSUserDefaults standardUserDefaults] objectForKey:"MyNameForThe240"]; 

You probably want them in a mutable array:

 NSMutableArray* the240ThatCanBeEdited = [NSMutableArray arrayWithArray:savedBools]; 

Then at the output, save them with

 [[NSUserDefaults standardUserDefaults] setObject:the240ThatCanBeEdited forKey:@"MyNameForThe240"]; 
+1
source

All Articles