yyjson 0.10.0
A high performance C JSON library.
|
yyjson consists of two types of data structures: immutable and mutable.
Immutable | Mutable | |
---|---|---|
Document | yyjson_doc | yyjson_mut_doc |
Value | yyjson_val | yyjson_mut_val |
Please note that the data structures described in this document are considered private, and it is recommended to use the public API to access them.
Each JSON value is stored in an immutable yyjson_val
struct:
The type of the value is stored in the lower 8 bits of the tag
.
The size of the value, such as string length, object size, or array size, is stored in the higher 56 bits of the tag
.
Modern 64-bit processors are typically limited to supporting fewer than 64 bits for RAM addresses (Wikipedia). For example, Intel64, AMD64, and ARMv8 have a 52-bit (4PB) physical address limit. Therefore, it is safe to store the type and size information within the 64-bit tag
.
A JSON document stores all strings in a contiguous memory area.
Each string is unescaped in-place and ended with a null-terminator.
For example:
A JSON document stores all values in another contiguous memory area.
The object
and array
containers store their own memory usage, allowing easy traversal of the child values.
For example:
Each mutable JSON value is stored in an yyjson_mut_val
struct:
The tag
and uni
fields are the same as the immutable value, and the next
field is used to build a linked list.
A mutable JSON document is composed of multiple yyjson_mut_val
.
The child values of an object
or array
are linked as a cycle,
the parent holds the tail of the circular linked list, enabling yyjson to perform operations append
, prepend
and remove_first
in constant time.
For example:
A JSON document (yyjson_doc
, yyjson_mut_doc
) is responsible for managing the memory of all its JSON values and strings. When a document it is no longer needed, it is important for the user to call yyjson_doc_free()
or yyjson_mut_doc_free()
to free the memory associated with it.
A JSON value (yyjson_val
, yyjson_mut_val
) has the same lifetime as its document. The memory is managed by its document and and cannot be freed independently.
For more information, refer to the API documentation.