|
|
Comments and Discussions
|
|
 |

|
thanks for the link!
do you know any site or anyone who can know anything about this?
regeards
Mariana
|
|
|
|

|
Hi,
not sure if this is the right forum to ask this, but perhaps someone can calrify this one for me.
I have a shared memory implementation similar to the one outlined here. I'm sharing data between instances of a DLL mapped into different processes.
So I create/open a named shared memory segment, get a handle, and then use the handle to MapViewOfFile and get a pointer to the beginning of the memory segment.
Now suppose I need to reallocate the amount of space that's shared in one of the instances of this DLL.
Would calling realloc on the pointer to the beginning of shared memory segment suffice? Since the value of this pointer could be different in every process, it seems to me that I would need to re-MapViewOfFile in all other instances, or does the Windows HANDLE abstraction take care of this for me.
Any insight would be awesome!
Thanks,
Timur
|
|
|
|

|
would this be easy to do?
thanks
|
|
|
|

|
I examine your function "SetValue" and "GetValue", and you use a CSingleLock to lock the value before read and write, a better way is to support multiple readers and single writers, viz. Readers/Writers problem.
|
|
|
|

|
Hi,
Im wondering does, this also work with pictures and other files?
greetz
|
|
|
|

|
when I use the class in two process A,B,and I use two shared variable dwA and dwB in the shared memory,the blocking happend.
the pseudo codes just like the following
first I run process A
process A:
while(true)
{
waitforvaluechage("dwA");
if(dwA==0xff)
{
setvalue("dwB",0xFF);
break;
}
setvalue("dwB",0x12);
}
then I run process B
process B:
int count=0;
while(true)
{
setvalue("dwA",count);
waitforvaluechange("dwB")
if(dwB==0xff)
break;
count ++;
}
when i run about 10 times,the prg blocking.how can i do?
|
|
|
|

|
Hi,
Your assuming the following:
process A Runs..
Process A Waits for change (dwA)
Process B Runs..
Process B changes (dwA)
Process B waits for change (dwB)
Process A resumes..
Process A changes (dwB)
etc..
But what could possibly happen is:
process A Runs..
Process A Waits for change (dwA)
Process B Runs..
Process B changes (dwA)
OS Scheduler switches to process A
Process A resumes..
Process A changes (dwB)
Process A Waits for change (dwA)
Process B waits for change (dwB)
DEADLOCK
|
|
|
|

|
This is a wonderfull code, the only thing I'll change would be the way you detect some versions of win95 (becose not work)
In the constructor:
...
....
TRACE(_T("osvi.dwMajorVersion = %d\n"),osvi.dwMajorVersion);
TRACE(_T("osvi.dwMinorVersion = %d\n"),osvi.dwMinorVersion);
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) //new line
{
if (osvi.dwMajorVersion >= 3) {
if ((osvi.dwMinorVersion == 51) ||
(osvi.dwMinorVersion == 0) ||
(osvi.dwMinorVersion == 1))
{
m_bSecPres = TRUE;
}
}
}
|
|
|
|

|
It works great on WIndows2000/XP, but on Windows98, sometimes, I mean seldom, the shared memory gets trespassed by other process, or say that the memory contents get altered with no valid reason. For example, I have process A and process B using the shared memory, none of them did any change to the shared memory, but after a while some of the memory contents get modified mystically.
This never happened on Windows 2000/XP, but did from time to time on Windows9x. My 2c, do not use system page file, use a private disk file instead, to do so, give a valid file handle value to the first parameter of "CreateFileMapping".
|
|
|
|

|
Friend of mine uses this class on Win95 and has no problems with altered memory contents.
I designed this class only for WinNT like systems and support for different versions has been added later only because of very small and not important project.
I think your suggestion about using file for sharing memory on Win95 may help, but the real problem lies somewhere else - you are running process which damages that memory accidentally (assuming from your description).
Martin
--------------------------------------------
C'mon we all know computers are experimental devices and should only be used for playing games.
Using them for alternative stuff like business, is clearly not using them for what they are intended.
Colin Davies
|
|
|
|

|
Hello,
Is there any way to use CArchive with this class? It would be slick to be able to Serialize data in in one process and Serialize it out in another.
Ted
|
|
|
|

|
There is no direct way to use CArchive with this class, however you can use 'Direct memory access methods' to store any data at any offset in the shared memory.
Martin
--------------------------------------------
C'mon we all know computers are experimental devices and should only be used for playing games.
Using them for alternative stuff like business, is clearly not using them for what they are intended.
Colin Davies
|
|
|
|

|
I have not compile it myself,sorry!
Please pardon my weak English!
|
|
|
|

|
Hi,
it does not support non-MFC, however, you might be able to cut out all referencies to MFC and replace 'MFC parts' with SDK versions.
Regards,
Martin
|
|
|
|

|
Ok,I am trying!
Thanks a lot!
Please pardon my weak English!
|
|
|
|

|
Send me your non-MFC version when you're done.]
It would be nice to publish it here as well. Many people would like non MFC version.
Thanks.
|
|
|
|

|
Hiyah from Sydney, Australia
this looks great, but Im having trouble compiling with it - I get C2501 'missing storage class or type specifiers' for each of the 'CSemaphore *m_pSync' and 'CSingleLock *m_pLock' declarations in SharedMemory.h (and it goes downhill from there)
My guess would be that I need to tell MFC to include Multithreaded support (I would likely do the same if I was on my other dev platform, Sun Solaris) .. but Im not sure what this means on MFC ...
does it mean that I have to :-
1) #include <afxmt.h>
2) (where ??) StdAfx.h ???
sorry, thats probably a real basic question, maybe by the time Ive spent some time tomorrow (Saturday) on it, I'll have the answer myself ... (just need some backup/reassurance )
ps ... (1) #include <afxmt.h> was gleaned from a quick web-scan .. I'll post back here when Ive tried it - one of the problems with where I live is, its GMT +10. This is well ahead of most of you in the USA, so I like to try and get questions out there early, so as maybe by the next day I'll have answers ...
Thanks for a great job in the classes, Im learning a lot here ..
Garth
|
|
|
|

|
Well, looks like I did manage to answer my own question - sorry if anyone was inconvenienced by this ..
the solution was as per :-
add a "#include <afxmt>" in StdAfx.h (with all the other 'Afx' includes)
I wonder if there's a way of indicating 'Multithreading support required' when one is using the wizard to start building an MFC program, but its a moot point now ..
Garth
|
|
|
|

|
It's great that you have a callback in your constructor to initialize the memory at allocation time. You might want to make this callback more C++ friendly either by adding a "user parameter" (an opaque void *) that is passed to the callback. That way, if my CFoo class is creating the shared memory, I can do this:
void CFoo::MakeMemory()
{
CSharedMemory* pNewBlock = new CSharedMemory("name", 1024, CFoo::Initializer, this);
}
void CFoo::Initializeer(CSharedMemory* pMem, void* p)
{
CFoo* This = (CFoo*) p;
}
Alternatively, if you want to go the "real" OO C++ route, you can make the callback a functor.
--
Tim Lesher
http://www.lesher.ws
|
|
|
|
|

|
Martin Ziacek wrote:
It is a lovely idea to pass one more parameter to callback function, however it has nothing to do with C++ at all.
Actually, it is a C++ issue, because it's the only way to get a C-style callback to call an object method (as opposed to a standalong function or a static method).
It seems like a minor thing, until you run across one of the few callbacks in the Windows API (SetTimer) that doesn't let you pass a user parameter, and you have to resort to hackery to get an object method called in response to it.
Tim Lesher
http://www.lesher.ws
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
Share variables in the shared memory across processes
| Type | Article |
| Licence | |
| First Posted | 6 Nov 2001 |
| Views | 140,095 |
| Downloads | 3,928 |
| Bookmarked | 76 times |
|
|