Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waste memory #491

Open
oneonce opened this issue Jul 31, 2020 · 2 comments
Open

Waste memory #491

oneonce opened this issue Jul 31, 2020 · 2 comments

Comments

@oneonce
Copy link

oneonce commented Jul 31, 2020

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
Copy link
Collaborator

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
Copy link

DBJDBJ commented May 8, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants