Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # memory-pager
  2. Access memory using small fixed sized buffers instead of allocating a huge buffer.
  3. Useful if you are implementing sparse data structures (such as large bitfield).
  4. ![travis](https://travis-ci.org/mafintosh/memory-pager.svg?branch=master)
  5. ```
  6. npm install memory-pager
  7. ```
  8. ## Usage
  9. ``` js
  10. var pager = require('paged-memory')
  11. var pages = pager(1024) // use 1kb per page
  12. var page = pages.get(10) // get page #10
  13. console.log(page.offset) // 10240
  14. console.log(page.buffer) // a blank 1kb buffer
  15. ```
  16. ## API
  17. #### `var pages = pager(pageSize)`
  18. Create a new pager. `pageSize` defaults to `1024`.
  19. #### `var page = pages.get(pageNumber, [noAllocate])`
  20. Get a page. The page will be allocated at first access.
  21. Optionally you can set the `noAllocate` flag which will make the
  22. method return undefined if no page has been allocated already
  23. A page looks like this
  24. ``` js
  25. {
  26. offset: byteOffset,
  27. buffer: bufferWithPageSize
  28. }
  29. ```
  30. #### `pages.set(pageNumber, buffer)`
  31. Explicitly set the buffer for a page.
  32. #### `pages.updated(page)`
  33. Mark a page as updated.
  34. #### `pages.lastUpdate()`
  35. Get the last page that was updated.
  36. #### `var buf = pages.toBuffer()`
  37. Concat all pages allocated pages into a single buffer
  38. ## License
  39. MIT