simdjson_php icon indicating copy to clipboard operation
simdjson_php copied to clipboard

Add `simdjson_free_memory(): int`

Open TysonAndre opened this issue 2 years ago • 1 comments

This may be useful if applications parse megabytes of json on startup, but don't use simdjson for large requests later on.

This would free the buffers used by the underlying C simdjson library

TysonAndre avatar Sep 28 '22 12:09 TysonAndre

simdjson_warn_unused
inline error_code dom_parser_implementation::allocate(size_t capacity, size_t max_depth) noexcept {
  if (this->max_depth() != max_depth) {
    error_code err = set_max_depth(max_depth);
    if (err) { return err; }
  }
  if (_capacity != capacity) {
    error_code err = set_capacity(capacity);
    if (err) { return err; }
  }
  return SUCCESS;
}

Most of the memory can be freed without this as a workaround by calling simdjson_decode('""') as a side effect of how the C library is implemented - it will always change the depth/capacity

TysonAndre avatar Sep 28 '22 13:09 TysonAndre