Skip to content

Handle sparse storage properly #17

@khernyo

Description

@khernyo

The current implementation doesn't seem to do sparse allocation like https://github.com/random-access-storage/random-access-memory.

In short: RandomAccessMemory::buffers should be of type Vec<Option<Vec<u8>>> instead of the current type Vec<Vec<u8>>.

I can see two problems with the current implementation:

  1. RandomAccessMemory::write() allocates all pages before page_num unnecessarily. See

    self.buffers.resize(page_num + 1, buf);

  2. RandomAccessMemory::del() seems to be broken. When removing a page it shifts all following pages thereby corrupting the stored data. Compare

    self.buffers.remove(i);
    to https://github.com/random-access-storage/random-access-memory/blob/da2d94570fc48674c22746b288bf65c3bf44015d/index.js#L93

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions