Developer Blog

Pro Tip: Do More With Connect IQ 2.4

11/01/17 @ 11:09 PM

We have already discussed the big features in Connect IQ 2.4, but we didn’t stop there; there are some other enhancements we made under the hood. These tweaks address some long-standing Connect IQ design decisions that have been holding back developers since version 1.0.

More Objects

Because Connect IQ devices may not have a memory management unit, the Connect IQ heap is designed to be self contained within a contiguous region of memory, and uses memory handles to track of addresses in the heap. What’s a memory handle you ask? You mean you never had to use GlobalLock to lock your Win16 memory handle? No? Well never mind then; if you need me, I’ll be crying about my wasted youth.

In previous versions Monkey C had a maximum of 512 memory handles. Any created object (except numbers, floats, booleans, and symbols) would count against both memory handles and heap space. This meant that on an Edge® 1000, which has 1 MB heap for Connect IQ apps, you could run out of memory handles well before you ran out heap memory. The 512 handle limit also meant we generally discouraged developers from using objects for pretty much anything.

In Connect IQ 2.4 the virtual machine will dynamically allocate handles when you are running low. Now new is your friend! Make everything a linked list! Now you just have to worry about running out of actual memory and not bookkeeping memory!

More Storage

Before we begin, it might help to have a refresher on what kinds of content are persisted to the file system.

  • Properties are constant values defined at build time in the resource property block. They are useful for product specific constants that shouldn’t be defined in code.
  • Settings are values that are user-editable through Garmin Connect Mobile
  • Storage are values that the application wants to persist across execution. They are written to disk

Since 1.0, application storage has been implemented as a dictionary, and this had a double cost to the developer. First, the dictionary lived at run time inside the developer heap, so storing any content would cost against your available heap. Second, the dictionary has a serialized size limit of 8 KB, and if the storage crossed over that limit it would not be written to disk. Double-whammy!

In Connect IQ 2.4 we introduce the Application.Properties and Application.Storage modules. Application.Properties provides an interface for accessing the values of properties and settings. Storage provides a new interface for persisting keys and values. Values persisted using Storage use a new on-disk database. Keys and values in the database are limited to 8 KB, and storing a value no longer costs against your heap usage! Even better, you now have 128 KB of storage - more memory than I could have imagined in my childhood!

API Level Properties Settings Storage
CIQ 1.x (Aikido Monkey) AppBase.getProperty
CIQ 2.4 (Biker Monkey) Application.Properties.getValue
AppBase.getProperty (uses 1.x storage)
AppBase.setProperty(uses 1.x storage)

If you are developing on a 2.4 compatible device, Storage offers a superior solution for persisting application data. It is important to note that this API will only be on Connect IQ 2.4 devices and above. If you’re trying to maximize the number of supported devices, use a Toybox.Application has :Storage check to see if the Storage API is available. Data stored using Storage will not be auto-migrated from data stored using AppBase to retain backwards compatibility.

You’re now free to create more objects and store more data!

Categories: Connect IQ SDK