The RAM required by any attribute is affected by the size and number of buffers to hold attribute data.
The buffer length, in bytes, is calculated as follows:
unit_buffer_length = max(max_attribute_value_byte_length, 4)
This equation reflects a requirement to align our buffers on four-byte boundaries.
For every attribute we maintain an actual and desired value, each value requiring a buffer. Total RAM required for attribute value-buffers is thus twice the unit_buffer_length:
buffer_length = (max(max_attribute_value_byte_length, 4) * 2)
Below are a couple examples of calculating total RAM requirement for attributes:
(max(1, 4) * 2) = 8 bytes
(max(8, 4) * 2) = 16 bytes
Latched attributes require an additional two buffers so the formula becomes:
latched_value_buffer_length = (max(max_value_byte_length, 4) * 4)
As an example, for a latched SINT8 attribute the value-buffer length would be:
(max(1, 4) * 4) = 16 bytes
The general formula for calculating the size of a profile in RAM is as follows:
Profile Size = Profile Overhead + sum((attribute overhead + value_buffer_length) for each attribute)
This general formula can be used for any MCU attribute
GPIO attributes (both unlatched and latched) have an internal structure that affects memory usage. These cases are all detailed in the table below:
|Profile Overhead||16 bytes||Version, attribute count, pointers to other structs.|
|Attribute Overhead||28 bytes||This is the general attribute overhead for all attribute types. It includes flags, values, and other pointers.|
|Attribute Overhead (latched)||Basic Attribute Overhead + 16 = 44 bytes||Latched attributes require additional fields.|
|MCU Attribute||Attribute Overhead + value_buffer_length||Examples:
Size for a SINT8 or BOOLEAN attribute =
28 bytes overhead + 8 bytes value attribute length = 36 bytes.
Size for a 255 byte UTF8S or BYTES attribute =
28 bytes overhead + 510 bytes value attribute length = 538 bytes.
|GPIO Attribute (non-latched)||80 bytes||
GPIO attributes are actually two attributes that have a fixed length. The value attribute is SINT16 and the configuration attribute is SINT64.
|GPIO Attribute (latched)||104 bytes||
Latched GPIOs have a larger per-attribute overhead plus two more value buffers:
(16 bytes latched value attribute length + 44 bytes overhead, latched) +
If you are building a profile and need to calculate the amount of RAM required for your attributes, the formula is:
(RAM Available for Profile - Profile Overhead) / Attribute Total Bytes
The total profile size is based on attribute type(s) as well as the size of the attribute value(s).
Given that the RAM available for profiles is 4kB, we can calculate the maximum number of attributes a profile can contain:
16 + (4 * 80) = 336 bytes
16 + (4 * 104) = 432 bytes
(4096 - 16) / 36 = 113 attributes
(4096 - 16) / 538 = 7 attributes