mirror of
https://github.com/nlohmann/json.git
synced 2026-10-12 10:13:13 +00:00
A new section describes the 16-byte node: its fields, how integers, floats, and object members are stored, how views navigate without pointers, and a worked example. The feature page and the pages of basic_json_document and node_count link to it where they mention the 16 bytes. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1.1 KiB
1.1 KiB
nlohmann::basic_json_document::node_count
std::size_t node_count() const noexcept;
Returns the number of entries in the document's flat index.
Return value
The number of index entries: one per value (of any type, at any nesting depth) plus one per object key. 0 for a
discarded document.
Exception safety
No-throw guarantee: this function never throws exceptions.
Complexity
Constant.
Notes
Each index entry is 16 bytes, so #!cpp node_count() * 16 is
the size of the index itself (part, but not all, of memory_usage(), which also counts decoded
strings and, for an owned document, the text).
Examples
??? example
```cpp
--8<-- "examples/basic_json_document__node_count.cpp"
```
Output:
```json
--8<-- "examples/basic_json_document__node_count.output"
```
See also
- memory_usage - the number of bytes held by the document
- shrink_to_fit - release unused index capacity
Version history
- Added in version 3.13.0.