Page 1 of 1

How to use external RAM in cJSON.C calls

Posted: Fri Jan 31, 2020 9:14 am
by sfarras
Hello everyone,
How can I force all malloc() calls in cJSON.c to use the external SPI RAM ?
I tried to reduce "CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL" to minimum in menuconfig, but I'm building a big JSON object composed by a lot of small objects and I suspect the result is stored mainly in internal RAM..
If I reduce CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL to 0, some parts like OTA functions doesn't work anymore.
I would like to force all functions of cJSON.c like CreateObject(); cJSON_CreateArray(); cJSON_CreateNumber(); ...etc... to use ONLY external SPI RAM.

Thank you in advance !!

Re: How to use external RAM in cJSON.C calls

Posted: Fri Jan 31, 2020 11:49 am
by ESP_Sprite
I think you're able to tell cJSON which allocators to use:

Code: Select all

	cJSON_Hooks memoryHook;

	memoryHook.malloc_fn = my_malloc;
	memoryHook.free_fn = free;
	cJSON_InitHooks(&memoryHook);
my_malloc should then be a function that explicitly returns a block allocated in SPI RAM.