Skip to content

Commit

Permalink
Use a global variable to track last shared buffer so it can be detach…
Browse files Browse the repository at this point in the history
…ed across lmdb instances, #173
  • Loading branch information
kriszyp committed May 26, 2022
1 parent fcfa5b2 commit 8152720
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lmdb",
"author": "Kris Zyp",
"version": "2.4.3",
"version": "2.4.4",
"description": "Simple, efficient, scalable, high-performance LMDB interface",
"license": "MIT",
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions read.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function addReadMethods(LMDBStore, {
if (rc == -30781 /*MDB_BAD_VALSIZE*/ && this.writeKey(id, keyBytes, 0) == 0)
throw new Error(id === undefined ?
'A key is required for get, but is undefined' :
'Zero length key is not allowed in LMDB')
'Zero length key is not allowed in LMDB');
if (rc == -30000) // int32 overflow, read uint32
rc = this.lastSize = keyBytesView.getUint32(0, true);
else
Expand Down Expand Up @@ -85,9 +85,9 @@ export function addReadMethods(LMDBStore, {
}
if (this.lastSize > NEW_BUFFER_THRESHOLD && !compression) {
// for large binary objects, cheaper to make a buffer that directly points at the shared LMDB memory to avoid copying a large amount of memory, but only for large data since there is significant overhead to instantiating the buffer
if (this.lastShared && detachBuffer) // we have to detach the last one, or else could crash due to two buffers pointing at same location
detachBuffer(this.lastShared.buffer);
return this.lastShared = getShared();
if (globalThis.__lmdb_last_shared__ && detachBuffer) // we have to detach the last one, or else could crash due to two buffers pointing at same location
detachBuffer(globalThis.__lmdb_last_shared__.buffer);
return globalThis.__lmdb_last_shared__ = getShared();
}
// grow our shared/static buffer to accomodate the size of the data
bytes = this._allocateGetBuffer(this.lastSize);
Expand Down

0 comments on commit 8152720

Please sign in to comment.