You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/basics.md
+11-4Lines changed: 11 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,12 @@ dom::parser parser;
58
58
dom::element doc = parser.parse("[1,2,3]"_padded); // parse a string
59
59
```
60
60
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
+
62
67
63
68
Using the Parsed JSON
64
69
---------------------
@@ -85,11 +90,13 @@ Once you have an element, you can navigate it with idiomatic C++ iterators, oper
85
90
* **Array Index:** To get at an array value by index, use the at() method: `array.at(0)` gets the
86
91
first element.
87
92
> 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.
91
95
* **Array and Object size** Given an array or an object, you can get its size (number of elements or keys)
92
96
with the `size()` method.
97
+
* **Checking an Element Type:** You can check an element's type with `element.type()`. It
0 commit comments