Solved

Should objects in share mem regions be volatile?

Posted on 2006-11-26
3
275 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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++.

749 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