Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Unlike other engines, memdown stores passed Buffers by reference #207

@abacabadabacaba

Description

@abacabadabacaba

Most abstract-leveldown stores store the data by value. Thus, when a method such as put is called with a Buffer, they record a byte sequence that it represents and store that.

Unlike other stores, memdown stores JavaScript values as is. The problems with that is that Buffer values are mutable: their underlying memory, and thus the byte sequence that they represent, may legitimately change. In general, such changes are not expected to have a side effect of changing the contents of an abstract-memdown store, but this is what happens with memdown, because it doesn't copy the Buffer values.

Not only it makes testing more difficult (memdown cannot be used as a drop-in replacement of another store for testing), it can also result in inconsistent behavior if the ordering of keys is violated.

I think that memdown's behavior should be changed to copy Buffer values, to match the behavior of other stores. A constructor options may be provided to turn off the copying as an optimization (which will require, however, that any code using memdown does not modify the underlying memory of any passed or returned Buffer).

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionDiscussionstaleThis issue or pull request is old

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions