Skip to content

Commit ac0e6c5

Browse files
authored
Update basics.md
1 parent f397b6f commit ac0e6c5

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

doc/basics.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ dom::parser parser;
5858
dom::element doc = parser.parse("[1,2,3]"_padded); // parse a string
5959
```
6060

61-
The parsed document resulting from the `parser.load` and `parser.parse` calls depends on the `parser` instance. Thus the `parser` instance must remain in scope. Furthermore, you must have at most one parsed document in play per `parser` instance. Calling `parse` or `load` a second time invalidates the previous parsed document. If you need access simultaneously to several parsed documents, you need to have several `parser` instances. For best performance, a `parser` instance should be reused.
61+
The parsed document resulting from the `parser.load` and `parser.parse` calls depends on the `parser` instance. Thus the `parser` instance must remain in scope. Furthermore, you must have at most one parsed document in play per `parser` instance.
62+
63+
During the`load` or `parse` calls, neither the input file nor the input string are ever modified. After calling `load` or `parse`, the source (either a file or a string) can be safely discarded. All of the JSON data is stored in the `parser` instance.
64+
65+
For best performance, a `parser` instance should be reused over several files: otherwise you will needlessly reallocate memory, an expensive process. It is also possible to avoid entirely memory allocations during parsing when using simdjson. [See our performance notes for details](https://github.com/simdjson/simdjson/blob/master/doc/performance.md).
66+
6267

6368
Using the Parsed JSON
6469
---------------------
@@ -85,11 +90,13 @@ Once you have an element, you can navigate it with idiomatic C++ iterators, oper
8590
* **Array Index:** To get at an array value by index, use the at() method: `array.at(0)` gets the
8691
first element.
8792
> Note that array[0] does not compile, because implementing [] gives the impression indexing is a
88-
> O(1) operation, which it is not presently in simdjson.
89-
* **Checking an Element Type:** You can check an element's type with `element.type()`. It
90-
returns an `element_type`.
93+
> O(1) operation, which it is not presently in simdjson. Instead, you should iterate over the elements
94+
> using a for-loop, as in our examples.
9195
* **Array and Object size** Given an array or an object, you can get its size (number of elements or keys)
9296
with the `size()` method.
97+
* **Checking an Element Type:** You can check an element's type with `element.type()`. It
98+
returns an `element_type`.
99+
93100
94101
Here are some examples of all of the above:
95102

0 commit comments

Comments
 (0)