Adding dynamic memory allocation.

This commit is contained in:
Daniel Lemire
2018-12-06 21:44:26 -05:00
parent 8589a0588b
commit c2913d5d69
7 changed files with 93 additions and 24 deletions
+12
View File
@@ -23,3 +23,15 @@ bool json_parse(const u8 *buf, size_t len, ParsedJson &pj) {
return isok;
}
WARN_UNUSED
ParsedJson build_parsed_json(const u8 *buf, size_t len) {
ParsedJson pj;
bool ok = pj.allocateCapacity(len);
if(ok) {
ok = json_parse(buf, len, pj);
assert(ok == pj.isValid());
} else {
std::cerr << "failure during memory allocation " << std::endl;
}
return pj;
}