c++ - How read a boost mapped_region object like a binary file? -


i mapped binary file memory following tutorial using boost library cannot figure out how iterate on binary object same way i'm using ifstream when open directly:

this code

#include <boost/interprocess/file_mapping.hpp> #include <boost/interprocess/mapped_region.hpp>  ...  file_mapping m_file(shmfile.c_str(), read_write); mapped_region region(m_file, read_write); 

i want that:

ifstream myfile (region.get_address(), std::ios::in); struct stat filestatus; sstemp = filename.str(); const char * c = sstemp.c_str(); stat(c, &filestatus); size = filestatus.st_size; int cant = 0;  while (cant < size) {      myfile.read((char *) user_id, 4);        cant += 4; } 

is there way it?

i cannot figure out how iterate on binary object same way i'm using ifstream when open directly

well, if want use when readin binary file, why using else?

maybe want this:

file_mapping m_file(shmfile.c_str(), read_write); mapped_region region(m_file, read_write);  char const* = region.data(); char const* e = + region.size();  (; (it+4) <= e; += 4) {      auto user_id = *reinterpret_cast<uint32_t const*>(it); } 

then again, shared memory, i'd use in managed fashion (e.g. using boost interprocess managed memory segment managers)


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -