| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C++ (Non Visual C++ Issues) Ask or answer C and C++ questions not related to Visual C++. This includes Console programming, Linux programming, or general ANSI C++. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Memory problem in C
Hi:
I'm trying to do this: -A C program write the memory pointer to one of its structures in a file (ex: 00278F92). And after that, he waits in execution. -Another C Program begins its execution, open the file, catch 00278F92, and use it to point the structure (which is defined too in this second program of course). Then it begin to search in this structure, but it fails. At one moment i see that he's pointing to FFFFFFFF. If I write exactly the same code in the first program, something like this newstruct=0x00278F92; search(newstruct); It works fine! So I think this is a problem with shared memory or similar, the first program don't let the second to see "its" memory. Anybody knows how to work like this? What to doing? Thanks. A lot of thanks! |
|
#2
|
||||
|
||||
|
This depends on your operating system. Most OSes these days give each process a virtual memory layout, which means that program a) can think its data is at 0x00278F92 and program b) thinks its data is at 0x00278F92, but yet these two adresses physically map to different memory.
__________________
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily. Supports C++ and VB out of the box, but can be configured for other languages. |
|
#3
|
|||
|
|||
|
and any idea about what to do?
|
|
#4
|
||||
|
||||
|
well it depends on what you are attempting to do...just use a filemapping (CreateFileMapping(...) etc) if you want to transfer data back and forth via an IPC, otherwise use OpenProcess(...) and ReadProcessMemory(...)
|
|
#5
|
||||
|
||||
|
Quote:
__________________
Get this small utility to do basic syntax highlighting in vBulletin forums (like Codeguru) easily. Supports C++ and VB out of the box, but can be configured for other languages. |
|
#6
|
|||
|
|||
|
XP, but i want to make it work at 2000 server.
I'll look at the fuctions Micks say me. |
|
#7
|
|||
|
|||
|
My Processes and Address Spaces might help you to understand about memory.
There are many Interprocess Communications (IPC) capabilities, and Mick mentioned a couple. (Actually I think that filemapping is the only IPC capability that Mick mentioned; I think that ReadProcessMemory is not normally considered an IPC solution.) The best solution depends on your requirements; the easiest is the WM_COPYDATA message. |
|
#8
|
||||
|
||||
|
Quote:
|
|
#9
|
|||
|
|||
|
The WM_COPYDATA message uses filemapping. The WM_COPYDATA message is definitely the most efficient for us (the programmer). So it depends on requirements, but an individual WM_COPYDATA message seems to me to be as efficient for Windows as if we were to code the filemapping ourselves and the WM_COPYDATA message would be immensely more efficient for us to program.
|
|
#10
|
||||
|
||||
|
Quote:
|
|
#11
|
||||
|
||||
|
Quote:
WriteProcessMemory(...) Signal write sync object (Mutex) other proc process data, signal read sync object. ReadProcessMemory(...) rinse and repeat I-P-C |
|
#12
|
|||
|
|||
|
Sometimes the savings in machine time do not justify the cost of people time. It depends on the situation and the programmer. Are you saying that the WM_COPYDATA message is never practical?
|
|
#13
|
||||
|
||||
|
Quote:
|
|
#14
|
|||
|
|||
|
Quote:
My definition of "normally considered an IPC solution" is something in the Interprocess Communications section of the Platform SDK. If you want to use a different definition of IPC, then you can, as long as it is clear that it differs from the Platform SDK definition. |
|
#15
|
||||
|
||||
|
Quote:
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|