I am trying memory map a map with key and value data type as string following this blog. But i'm getting lots of error including above error. How can i fix it? Is their other method to memory map a file with map values of key and value type string accurately? Here's the code which i tried.
#include<iostream>
#include<map>
#include<string>
*mmap_start = (void*)139731133333504;
size_t offset = 1024;
template <typename T>
class MmapAlloc {
pointer allocate(size_t num, const void *hint = 0) {
long returnvalue = (long)mmap_start + offset;
size_t increment = num * sizeof(T) + 8;
increment -= increment % 8;
offset += increment;
return (pointer)returnvalue;
}
};
typedef std::basic_string<char, std::char_traits<char>, MmapAlloc<char>> mmapstring;
typedef std::map<mmapstring, mmapstring, std::less<mmapstring>,MmapAlloc<mmapstring> > mmapmap;
int main(int argc, char **argv) {
int fd = open("backingstore.dat", O_RDWR);
void *mapping;
mapping = mmap(mmap_start, 10*1024*1024,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
if(mapping == MAP_FAILED) {
printf("MMap failed.\n");
return 1;
}
mmapstring key("key");
mmapstring value("value");
if(fd < 1) {
printf("Open failed.\n");
return 1;
}
auto map = new(mapping)mmapmap();
(*map)[key] = value;
printf("Sizeof map: %ld.\n", (long)map->size());
printf("Value of 'key': %s\n", (*map)[key].c_str());
return 0;
}
Aucun commentaire:
Enregistrer un commentaire