Skip to main content
gamedev.net
🔒 Locked

shared memory not really shared?

Started by spiralmonkey 1 reply 400+ views
Original Post
spiralmonkey
spiralmonkey
hey all, i'm experiencing some confusion regarding shared memory. I have 2 applications running, one of which allocated memory using GlobalAlloc(GMEM_FIXED,size) and passed the memory pointer to the other program. I've verified that the 2 programs both have a pointer to the same memory location (the number is the same). however, if i change the memory contents with one, the other doesn't see it. they read back only the values they're setting, not the value the OTHER program is setting it to. Am i misunderstanding how shared memory works? what i'm trying to do is create an externally controlled log-managing program. I'd like my main program to send its log output to a chunk of memory controlled by my logging program (running at the same time), so if my main program crashes, my log program can still save out the data. the reason i'm not just dumping the log to a file is that the file gets too large (and writing to disk is slow) - i only want to save the last part of the log if my main program crashes. any ideas? thanks, alan
BeanDog
BeanDog
Just because the numbers are the same does not mean that they point to the same place in memory. Each process has its own addressing space. Think of pointers as offsets from the beginning of that application's space in memory, and you see why your changes don't propogate between programs. In fact, writing to that pointer in the other process could have catastrophic results.



~BenDilts( void );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.