Using boost interprocess features from inside Class member functions
Hi All Am facing a lot of issue while using interprocess features inside my class file. I am pasting my class file below: class MyClass{ Ref* ref; public: MyClass(); void initializeBuffers(); void processMessage(); ~MyClass(); }; void MyClass::createBuffer() { shared_memory_object::remove("test"); shared_memory_object shm(open_or_create, infoBufferName, read_write); shm.truncate(sizeof(ServerDetails)); mapped_region region(shm, read_write); void* addr = region.get_address(); ref=new (addr) Ref; ref->value=50; } void MyClass::processMessage() { printf("%d",ref->value); //I get a segmentation fault in here. } int main() { MyClass c(); c.createBuffer(); c.processMessage(); } When I execute this I am getting segmentation exception. If I merge processMessage and createBuffer under same function it starts working. But if in any case I change the function signature to have an argument again this issue starts. Am not sure if I am doing some thing wrong above. Please do help me on this. Error I get is: Program received signal SIGSEGV, Segmentation fault. 0x77d41df8 in ntdll!RtlGetCompressionWorkSpaceSize () from C:\Windows\system32\ntdll.dll -- Achu
El 04/05/2012 23:47, Achuth Sankar escribió:
Hi All
Am facing a lot of issue while using interprocess features inside my class file. I am pasting my class file below:
when "mapped_region" is destroyed, then the shared memory is unmapped and you have no acces to it. Make mapped_region a member of your class. void MyClass::createBuffer() { shared_memory_object::remove("test"); shared_memory_object shm(open_or_create, infoBufferName, read_write); shm.truncate(sizeof(ServerDetails)); mapped_region region(shm, read_write); void* addr = region.get_address(); ref=new (addr) Ref; ref->value=50; //Assign the recently created mapped region to the internal member m_member_mapped_region = boost::move(region); } best, Ion
Hi Ion
Thanks a lot Ion, you saved my day. Let me try this out tomorrow. Was stuck
with this for a week.
regards
Achuth
On Sun, May 6, 2012 at 4:03 PM, Ion Gaztañaga
El 04/05/2012 23:47, Achuth Sankar escribió:
Hi All
Am facing a lot of issue while using interprocess features inside my class file. I am pasting my class file below:
when "mapped_region" is destroyed, then the shared memory is unmapped and you have no acces to it. Make mapped_region a member of your class.
void MyClass::createBuffer() { shared_memory_object::remove("**test"); shared_memory_object shm(open_or_create, infoBufferName, read_write); shm.truncate(sizeof(**ServerDetails)); mapped_region region(shm, read_write); void* addr = region.get_address(); ref=new (addr) Ref; ref->value=50; //Assign the recently created mapped region to the internal member m_member_mapped_region = boost::move(region); }
best,
Ion ______________________________**_________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**usershttp://lists.boost.org/mailman/listinfo.cgi/boost-users
-- be late to be great hoida !!!
participants (2)
-
Achuth Sankar
-
Ion Gaztañaga