You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, in embedded devices like the ESP32, using the 'int' type implies using 32 bits, which is often unnecessary. If you then need to use an array of this struct, it could consume a lot of stack memory. This is why I propose using uint16_t in the following way:
Definition of the data type for the indices in the jsmntok_t structure.
It can be configured based on the environment using the USE_JSMNTYPE_UINT16 macro.
If defined, uint16_t is used to reduce memory consumption in embedded systems.
Otherwise, a larger integer type (default: int) is used.
*/
#ifdef USE_JSMNTYPE_UINT16
typedef uint16_t jsmn_index_t;
#else
typedef int jsmn_index_t; // Or any other default type
#endif
Cool idea. Would be good to also ensure JSMN defends itself against overflows. Could be a feature hidden behind a millionth ifdef.
But being able to choose a smaller type for index could be very beneficial if you only expect small JSON strings.
Sometimes, in embedded devices like the ESP32, using the 'int' type implies using 32 bits, which is often unnecessary. If you then need to use an array of this struct, it could consume a lot of stack memory. This is why I propose using uint16_t in the following way:
#Iifdef USE_JSMNTYPE_UINT16
typedef struct jsmntok {
jsmntype_t type;
uint16_t start;
uint16_t end;
uint16_t size;
#ifdef JSMN_PARENT_LINKS
uint16_t parent;
#endif
} jsmntok_t;
#endif
The text was updated successfully, but these errors were encountered: