Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Should objects in share mem regions be volatile?

Posted on 2006-11-26
3
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

715 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