Repository navigation
use memory mapped files for the peer buffer - #12
Conversation
| enum { header_size = 16 }; | ||
| mapped_vector(char const* file, size_t const size) | ||
| : m_map(file, header_size + size * sizeof(T)) | ||
| , m_size(*static_cast<size_t*>(m_map.data())) |
There was a problem hiding this comment.
This should be reinterpret_cast since you're transmuting the data rather than downcasting.
There was a problem hiding this comment.
Never mind, I double checked the C++ spec and static_cast can indeed be used to convert void* to T*. Learn something new every day.
|
one questionable thing, I think, is that the header size is not technically guaranteed to be a multiple of alignof(T) in mapped_vector. That should actually be pretty easy to fix. |
| return; | ||
| } | ||
|
|
||
| this->threadid = threadid; |
There was a problem hiding this comment.
I moved the thread id around a bit here, to have it be available in the constructor, in order to create unique names for the mapped files
|
lgtm, it would probably be a good idea to check the last modified time of the file and discard it if it is too old. |
|
Yeah, I was thinking about that too. I got a bit lazy and thought that the user could always just delete the file :) |
|
ok, fixed the alignment of T too |
| enum { header_size = 16 }; | ||
| // the header must be large enough to make the first element still be | ||
| // correctly aligned | ||
| static constexpr size_t header_size = std::max(size_t(16), alignof(T)); |
There was a problem hiding this comment.
std::max isn't constexpr in C++11, I don't think the qualifier is necessary in this case.
|
lgtm |
771333b to
cb2d2cf
Compare
|
rebased on top of master again |
to preserve state between restarts with some simple unit tests