Solved

Shared Memory and inheritance

Posted on 1998-03-27
1
197 Views
Last Modified: 2013-12-03
I am currently using CreateFileMapping() and MapViewOfFile() to create a block of shared memory using 0xFFFFFFFF as the first parameter of the CreatFileMapping() call so its not associated with a file but uses the system paging file.



However, by giving it a name "MY_SHARED_MEM", so both processes will attach to the same area, this leaves me with a problem.



At some point in time, these applications may run on an NT server and so there may be multiple processes running. I only want the main process and the child process *of that main process* to access the shared memory. As it is, I 'think' that if another uses starts a 2nd main process and launches the child, they will attach to the original area, becuase of the name correct?



How can I avoid this, and yet still use the system paging file? . use the CreateProcess to launch the child with handle inheritance set to TRUE if thats necessary to do this. I've read about DuplicateHandle() but not sure how to set it up..can't quite get a grasp on it.



Any help would be appreciated
0
Comment
Question by:gunn
1 Comment
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 110 total points
ID: 1412338
This is not that unusual. One idea is to not hardcode a specific name, but to use one based off of the processId of the parent. For example, instead of using MY_SHARED_MEM as the name of the filemap, use MY_SHARED_MEM_%PROCESSID%. Then when the parent process launches the child, pass the child the name as an argument.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

23 Experts available now in Live!

Get 1:1 Help Now