cJSON icon indicating copy to clipboard operation
cJSON copied to clipboard

Waste memory

Open oneonce opened this issue 5 years ago • 2 comments

typedef struct cJSON { struct cJSON *next, *prev; struct cJSON *child; int type; char *valuestring; int valueint; double valuedouble; char *string; } cJSON;

size_t size = sizeof(cJSON) = 40

typedef struct cJSON { struct cJSON *next, *prev; struct cJSON *child; int type; char *string; union Value { char *valuestring; //int valueint; // can not save 0xFFFF FFFF FFFF FFFF int64_t valuelong; // can save 0xFFFF FFFF FFFF FFFF double valuedouble; } value; } cJSON;

size_t size = sizeof(cJSON) = 32

when we use cJSON for embedded device(such as: ARM Cortex M3/M4/M7), the memory is very small.

oneonce avatar Jul 31 '20 02:07 oneonce

cJSON has plans to use union in the future(milestone 2.0.0), for details, please see #63. But int64_t is incompatible with c89, it may not be acceptable in the short term.

Alanscut avatar Jul 31 '20 02:07 Alanscut

https://github.com/zserge/jsmn

DBJDBJ avatar May 08 '21 16:05 DBJDBJ