How to use external RAM in cJSON.C calls

sfarras
Posts: 2
Joined: Tue Apr 10, 2018 2:58 pm

How to use external RAM in cJSON.C calls

Postby sfarras » Fri Jan 31, 2020 9:14 am

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 !!

ESP_Sprite
Posts: 9725
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Fri Jan 31, 2020 11:49 am

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.

Who is online

Users browsing this forum: Bing [Bot] and 95 guests