Hello!
I am filling a cJSON Array with AddNumberToObject() function. At first it works fine, but at some point the add_item_to_object() function within AddNumberToObject() begins to return NULL, thus not writing the number and producing afterwards the error "LoadProhibited", when dereferencing the null pointer (char *) to this Array rendered as text.
The cJSON Array I am trying to create is quite large: 3200 times AddNumberToObject() function.
Is there maybe a maximum size for a cJSON array? Or am I simply running out of memory in ESP32?
Any help would be really appreciated.
ESP32 & cJSON - Fail to create large cJSON arrays
Re: ESP32 & cJSON - Fail to create large cJSON arrays
I took a quick look at the cJSON implementation and yes, at 3200 add(s), I am confident you are hitting the heap ceiling. It’s not a limitation of cJSON itself. There isn’t much that can go wrong in AddNumberToObject other than an allocation failure.
Never assume something succeeded, check results and fail early.
To whom it may concern (at Espressif) in regards to cJSON in IDF:
I noticed that cJSON doesn’t store its “generic” data items into a union; so the cJSON data structs always have some unused members depending on the datatype being stored. Granted, it probably would not have made the difference here; but for 3200 items it would save ~25K in struct overhead. Just saying.
Regards
Never assume something succeeded, check results and fail early.
To whom it may concern (at Espressif) in regards to cJSON in IDF:
I noticed that cJSON doesn’t store its “generic” data items into a union; so the cJSON data structs always have some unused members depending on the datatype being stored. Granted, it probably would not have made the difference here; but for 3200 items it would save ~25K in struct overhead. Just saying.
Regards
Re: ESP32 & cJSON - Fail to create large cJSON arrays
You were completely right, I was running out of heap space, thank you!
Solution to this is quite straightforward though: create many smaller arrays and send/free them one by one, instead of a larger one
Solution to this is quite straightforward though: create many smaller arrays and send/free them one by one, instead of a larger one
Who is online
Users browsing this forum: No registered users and 95 guests