tenderlove / mmap

A wrapper around mmap
63 stars 14 forks source link

Add support for updating and inserting bare numbers #10

Closed raydefy closed 4 years ago

raydefy commented 5 years ago

I needed to share integers between two processes and wanted to use mmap. While it supports #insert of strings, it did not support the same for numbers. I'm note sure I sized things right, but the tests pass.

tenderlove commented 5 years ago

I need to think about this more, but my initial question is why not use pack / unpack (or marshal) to convert to a string?

raydefy commented 4 years ago

I was planning on using mmap to share performance counters from a Ruby program with another program. I don't know if there is any performance benefit to avoiding pack/unpack. I should have tested that.

In any case, I sized the Int as a byte. It should have been at least 4 bytes. The pack/unpack would avoid all that non-sense.

raydefy commented 4 years ago

Upon reflection, I think the pack/unpack is a perfect Ruby approach. We don't need to complicate the API by making Integer any more special than they already are.

raydefy commented 4 years ago

Here we see the exact use case I was working toward. But he ditches mmap for a file. https://www.youtube.com/watch?v=crbyeyPS7HE&list=TLPQMTgxMjIwMTmkP6JczWLARQ&index=2