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
* Improving portability.
* Revisiting faulty logic regarding same-page overruns.
* Disabling same-page overruns under VS.
* Clarifying the documentation
* Fix for issue 131 + being more explicit regarding memory realloc.
* Fix for issue 137.
* removing "using namespace std" throughout. Fix for 50
* Introducing typed malloc/free.
* Introducing a custom class (padded_string) that solves several minor usability issues.
* Updating amalgamation for testing.
@@ -90,21 +88,49 @@ of memory allocation with each new JSON document:
90
88
/...
91
89
92
90
constchar * filename = ... //
93
-
std::string_view p = get_corpus(filename);
91
+
padding_string p = get_corpus(filename);
94
92
ParsedJson pj = build_parsed_json(p); // do the parsing
95
-
// you no longer need p at this point, can do aligned_free((void*)p.data())
96
93
if( ! pj.isValid() ) {
97
94
// something went wrong
98
95
}
99
-
aligned_free((void*)p.data());
100
96
```
101
97
102
-
You can call `json_parse` and `build_parsed_json`, passing a standard `std::string` object.
98
+
Though the `padded_string` class is recommended for best performance, you can call `json_parse` and `build_parsed_json`, passing a standard `std::string` object.
103
99
104
100
105
-
## Memory overallocation `
101
+
```C
102
+
#include"simdjson/jsonparser.h"
103
+
104
+
/...
105
+
std::string mystring = ... //
106
+
ParsedJson pj;
107
+
pj.allocateCapacity(mystring.size()); // allocate memory for parsing up to p.size() bytes
108
+
// std::string may not overallocate so a copy will be needed
109
+
constint res = json_parse(mystring, pj); // do the parsing, return 0 on success
110
+
// parsing is done!
111
+
if (res != 0) {
112
+
// You can use the "simdjson/simdjson.h" header to access the error message
// std::string may not overallocate so a copy will be needed
127
+
ParsedJson pj = build_parsed_json(mystring); // do the parsing
128
+
if( ! pj.isValid() ) {
129
+
// something went wrong
130
+
}
131
+
```
106
132
107
-
As needed, the `json_parse` and `build_parsed_json` functions copy the input data to a temporary buffer readable up to SIMDJSON_PADDING bytes beyond the end of the data. To avoid this potentially expensive copy, overallocate your own input data and then call the `json_parse` and `build_parsed_json` functions with an extra parameter value set to `false` (e.g., `build_parsed_json(p,false)` and `parsed_json(p,pj,false)`). In such instance, no temporary copy is made. The `get_corpus` function does this automatically as well as the provide `char * allocate_padded_buffer(size_t length)` function to achieve the desired effect.
133
+
As needed, the `json_parse` and `build_parsed_json` functions copy the input data to a temporary buffer readable up to SIMDJSON_PADDING bytes beyond the end of the data.
108
134
109
135
## Usage: easy single-header version
110
136
@@ -118,14 +144,13 @@ copy the files in your project in your include path. You can then include them q
118
144
#include"simdjson.cpp"
119
145
intmain(int argc, char *argv[]) {
120
146
const char * filename = argv[1];
121
-
std::string_view p = get_corpus(filename);
147
+
padded_string p = get_corpus(filename);
122
148
ParsedJson pj = build_parsed_json(p); // do the parsing
0 commit comments