persistent pointer/memory allocation
-
Hello All, A little question about memory allocation. Yes, nos and look heres greatly accepted... I'm not sure how to word the question so I'll say what I want to do: I want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up. Is this possible? Thanks...
-
Hello All, A little question about memory allocation. Yes, nos and look heres greatly accepted... I'm not sure how to word the question so I'll say what I want to do: I want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up. Is this possible? Thanks...
You can used shared memory, though the second program would have to start and open the shared memory before the first exited.
Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
Hello All, A little question about memory allocation. Yes, nos and look heres greatly accepted... I'm not sure how to word the question so I'll say what I want to do: I want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up. Is this possible? Thanks...
Hi, Have a look at "memory mapped files"; these are files mapped into memory, or memory blocks mapped to an actual file, depending how you look at it. :)
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
-
Hello All, A little question about memory allocation. Yes, nos and look heres greatly accepted... I'm not sure how to word the question so I'll say what I want to do: I want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up. Is this possible? Thanks...
Ylno wrote:
. When this program finished I do not want to free up this memory location
This is not an option. It is freed or marked as free by the OS. And could possibly be immediately used by another program and the earlier contents erased. You should use persistent storage. Files, Registry ...
«_Superman_» I love work. It gives me something to do between weekends.
-
Hello All, A little question about memory allocation. Yes, nos and look heres greatly accepted... I'm not sure how to word the question so I'll say what I want to do: I want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up. Is this possible? Thanks...
Ylno wrote:
When this program finished I do not want to free up this memory
Reminds me of good ol TSR.
Ylno wrote:
want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up.
We have something similar at work. Yes you can do it. But you should host an all-time "memory-server". It's a complex thing. You'll have to do quite a lot of marshalings. A new process *Cannot* just starting using memory from another application. I've used those "memory-serving" services but don't know the implementation details. But the abstract idea resembles DCOM.
He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus
-
Hello All, A little question about memory allocation. Yes, nos and look heres greatly accepted... I'm not sure how to word the question so I'll say what I want to do: I want to, from one program, allocate a block of memory noting its memory address/pointer. When this program finished I do not want to free up this memory location but rather be able to access it from a second program and be guarenteed of what I'll find there. Basically I want to be able to take this address and, in a completly seperate program, access this memory and then deacllocate/free it up. Is this possible? Thanks...
I like to keep as much as possible in RAM for fast read/write operations... my two suggestions: Option 1 you could create a RAM Drive, then just save to a file. The two program share the data by accessing the same file in turn. Option 2 You could also create a third program (that is started before the first program, and ends after the 2nd program) that sets up a shared file with CreateFileMapping():
char \* pMyFilePointer = NULL; HANDLE hMyFileHandle = CreateFileMapping((HANDLE)-1, NULL, PAGE\_READWRITE, 0, 10, "MySharedFile"); if (hMyFileHandle != NULL) { pMyFilePointer = (char \*) MapViewOfFile(hMyFileHandle, FILE\_MAP\_WRITE, 0, 0, 10); if (pMyFilePointer != NULL) { printf("file mapped to %p",pMyFilePointer); \*(pMyFilePointer+0) = (unsigned char)0; \*(pMyFilePointer+1) = (unsigned char)0xbb;
Then, your other two programs open the file with:
HANDLE hMyFileHandle;
char * pMyFilePointer;//open data share file hMyFileHandle = OpenFileMapping(FILE\_MAP\_WRITE, TRUE, "MySharedFile"); if (hMyFileHandle != NULL) { pMyFilePointer = (char \*) MapViewOfFile(hMyFileHandle,FILE\_MAP\_WRITE, 0, 0, 10); //example write operation \*pMyFilePointer = (unsigned char)0xAA; }