Solved

Should objects in share mem regions be volatile?

Posted on 2006-11-26
3
249 Views
Last Modified: 2010-04-01
Should an object placed in an IPC shared-mem region be declared volatile, to alert the compiler that the object's internal values could change at any time?  Or would that be useless unless the internal values themselves are declared volatile?

I have an object stored in a shared memory region.  I use placement new to build the object there.  Should I declare it volatile?
0
Comment
Question by:chsalvia
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 125 total points
ID: 18014761
I would not place any objects in a shared memory area at all in the 1st place., but that's a different thing. Yes, it would be a good idea to declare them as volatile to tell the compiler not to use them in optimizations. It would be even better to synchronize access to these objects, though.
0
 

Author Comment

by:chsalvia
ID: 18014905
>>I would not place any objects in a shared memory area at all in the 1st place

Why?  I realize there is a danger if the object contains a pointer to another memory area, but if the object is completely self-contained, what's the harm?

>> It would be even better to synchronize access to these objects, though.

But how would multiple processes be able to share the object, without shared mem?  I suppose each process could have a unique object, which uses a file to construct itself.  But that would be much slower than just using shared mem.

0
 
LVL 86

Expert Comment

by:jkr
ID: 18014945
Syncing access is something different, you have to take care that the data is not altered at the same time by different processes.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now