yyjson 0.6.0
A high performance C JSON library.
|
yyjson has two types of data structures: immutable and mutable.
Note that the data structures described in this document are private, and you should use the public API to access them.
Each JSON value is stored in an immutable yyjson_val
struct:
The lower 8 bits of tag
stores the type of value.
The higher 56 bits of tag
stores the size of value (string length, object size or array size).
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 in a 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
stores their own memory usage, so we can easily walk through a container's child values.
For example:
Each mutable JSON value is stored in an yyjson_mut_val
struct:
The tag
and uni
field is same as immutable value, the next
field is used to build 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, so that yyjson can do append
, prepend
and remove_first
in O(1) time.
For example: