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
// Even if you keep the old reference around, doc and doc2 refer to the same document.
34
34
cout << doc << endl;
35
35
cout << doc2 << endl;
36
36
```
37
37
38
-
It's not just internal buffers though. The simdjson library reuses the document itself. Notice that reference?
39
-
`document &doc`? That's key. You are only *borrowing* the document from simdjson, which purposely
40
-
reuses and overwrites it each time you call parse. This prevent wasteful and unnecessary memory
41
-
allocation in 99% of cases where JSON is just read, used, and converted to native values
42
-
or thrown away.
38
+
It's not just internal buffers though. The simdjson library reuses the document itself. document::element, document::object and document::array are *references* to the internal document.
39
+
You are only *borrowing* the document from simdjson, which purposely reuses and overwrites it each
40
+
time you call parse. This prevent wasteful and unnecessary memory allocation in 99% of cases where
41
+
JSON is just read, used, and converted to native values or thrown away.
43
42
44
43
> **You are only borrowing the document from the simdjson parser. Don't keep it long term!**
45
44
46
45
This is key: don't keep the `document&`, `document::element`, `document::array`, `document::object`
47
46
or `string_view` objects you get back from the API. Convert them to C++ native values, structs and
48
47
arrays that you own.
49
48
50
-
### Keeping documents around for longer
51
-
52
-
If you really need to keep parsed JSON documents around for a long time, you can **take** the
53
-
document by declaring an actual `document` value.
54
-
55
-
```c++
56
-
document::parser parser;
57
-
58
-
// This initializes buffers and a document big enough to handle this JSON.
59
-
// By casting to document instead of document&, it "steals" the document from the parser so that it
0 commit comments