Best practice: Using efficient data structure selection

Data structure selection defines how many object handles and how much flash memory an app consumes. Improper data structure selection can consume key resources without improving app functionality or the user experience.

Consider the following guidelines:

  • The data structure should consist of the least possible number of objects, especially when you use high-level objects like a Vector or a Hashtable. These classes provide significant functionality but are not efficient storage mechanisms and you should avoid using them in the persistent store if possible.
  • When possible, use primitives instead of objects, because primitives reduce the number of object handles that are consumed on the smartphone. An array of primitives is an object and consumes an object handle.
  • String objects are as efficient as byte arrays. A String object consumes only one object handle and is equivalent if your app stores all of the characters as a byte. In other words, the value of each character is less than or equal to the decimal value of 255. If your app can't store characters as a byte, you can store the characters as a String, which is equivalent to storing a char array.

Was this information helpful? Send us your comments.