You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Amazing library!
But I can suggest a pair of improvement.
I founded written no where that the file to be mapped need to be at least 1 byte, no big deal, but It took a bit to discovery.
If you do a
auto f = fopen("testfile", "w+");
auto fNo = fileno(f);
ftruncate(fNo,0);
using namespace mmap_allocator_namespace;
mmappable_vector<int, mmap_allocator > v =
mmappable_vector<int, mmap_allocator >(mmap_allocator("testfile", READ_WRITE_SHARED, 0, ALLOW_REMAP));
for (int var = 0; var < 50; ++var) {
v.push_back(var);
}
It will crash, I have no idea why this happen...
The second suggestion is when using mmap_allocator("testfile", READ_WRITE_SHARED, 0, ALLOW_REMAP)
The file should be ftruncate to the size of the mmaped region, or else the remaining part will be lost.
Due to having multiple mmaped region, I have no idea how to perform this truncate on the fly, If I find I will do a pull request (of course out of the library is just a ftruncate(file,vector.size() * sizeof (int));)
The text was updated successfully, but these errors were encountered:
Just discovered that even if I initialize the file to 1byte, if the vector grow over 1024, the same error will occour...
I do not know after which treshold and why, but the vector grow and realloc internally doubling it's size each time, so even if the size is "correct" it will stil fail for example in case of
ftruncate(fNo, 5000 * sizeof(int));
for (int var = 0; var < 5000; ++var) {
v.push_back(var);
}
Hi Roy, at the moment mmap_allocator does not support resizing the vector. It
is meant mainly for reading files that are already on disk. Supporting resizing
should be possible (via mremap()) however at the moment I am busy with
WinDRBD (www.github.com/Linbit/WinDRBD) ... If you wish to implement
resizing then please do, patches welcome ;)
The 1024 ints limit is easily explained by looking at PAGE_SIZE (which is
4KB on your system), mmap() uses pages to map the memory therefore
one can add some elements at the end of the vector if the last page
is not used completely.
The empty file bug definitately has to be fixed, I will try to find some time
and implement that in the next weeks.
Thanks for you input and for using mmap_allocator.
Amazing library!
But I can suggest a pair of improvement.
I founded written no where that the file to be mapped need to be at least 1 byte, no big deal, but It took a bit to discovery.
If you do a
auto f = fopen("testfile", "w+");
auto fNo = fileno(f);
ftruncate(fNo,0);
using namespace mmap_allocator_namespace;
mmappable_vector<int, mmap_allocator > v =
mmappable_vector<int, mmap_allocator >(mmap_allocator("testfile", READ_WRITE_SHARED, 0, ALLOW_REMAP));
It will crash, I have no idea why this happen...
The second suggestion is when using mmap_allocator("testfile", READ_WRITE_SHARED, 0, ALLOW_REMAP)
The file should be ftruncate to the size of the mmaped region, or else the remaining part will be lost.
Due to having multiple mmaped region, I have no idea how to perform this truncate on the fly, If I find I will do a pull request (of course out of the library is just a ftruncate(file,vector.size() * sizeof (int));)
The text was updated successfully, but these errors were encountered: