0

I hope this is the right forum to ask this sort of question. I'm trying to minimize the amount of data performing a sync with iCloud, while ensuring ideal app speed as well... I am trying to use an efficient model... My application (which is a basic checklist application) will have around 8 variables that can be marked as "owned" for each item.

Would it be better to create 8 attributes as Boolean attributes or a single String attribute? With the string attribute, I would simply include 8 numbers like "00000000" or "10000000" or "10001000" with each character of the string linked to a particular item and retrieved by looking for a particular index of the string.

My initial thought is that the 8 booleans would allow for faster reading and writing, and would have a minimal footprint, but I would appreciate some more intelligent feedback from the experts.

Zachary Fisher
  • 781
  • 1
  • 7
  • 18

2 Answers2

0

I would not recommend nothing of this to minimize memory usage. Reason is that bool costs 1 byte - 8 bit (but wee need only one and other 7 wont be used), string same but with characters. If you want to minimize memory usage - than use 1 byte. Because 1 byte - 8 bit you can set each bit with 1 or 0 using memory mask(bit mask). And than all your values will be allocated in 1 byte what will use eight time less memory than bool. How to use memory mask(bit mask) you can read this topic

Declaring and checking/comparing (bitmask-)enums in Objective-C

Community
  • 1
  • 1
Volodymyr
  • 1,165
  • 5
  • 16
0

I would think any difference in speed or memory is likely to be marginal. Design and code it in the most logical way, which at first sight seems to be using 8 booleans. For example, if you need to fetch a subset of the data based on the boolean values, it will be far easier to construct the required predicate.

pbasdf
  • 21,386
  • 4
  • 43
  • 75