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:
-
RandomAccessMemory::write() allocates all pages before page_num unnecessarily. See
|
self.buffers.resize(page_num + 1, buf); |
-
RandomAccessMemory::del() seems to be broken. When removing a page it shifts all following pages thereby corrupting the stored data. Compare
to https://github.com/random-access-storage/random-access-memory/blob/da2d94570fc48674c22746b288bf65c3bf44015d/index.js#L93