DaveGamble / cJSON

Ultralightweight JSON parser in ANSI C
MIT License
10.62k stars 3.2k forks source link

Waste memory #491

Open oneonce opened 4 years ago

oneonce commented 4 years ago

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.

Alanscut commented 4 years ago

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.

DBJDBJ commented 3 years ago

https://github.com/zserge/jsmn