Solved

Should objects in share mem regions be volatile?

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MSVCR80.dll crash 2 139
SendMessage fails while PostMessage works 2 114
Printing the elements of a set declared inside a map in C++. 3 47
c++ syntax question 9 48
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

773 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