954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to share memory between applications?

Hi everbody!

Sample problem:
program1 has a poiter that point to a block memory in PC memory.
program1 write the address of block memory (the pointer) in hard disk.
program1 still run.
program2 start.
program2 read the pointer (address of block memory) in the hard disk.
Now program1 and program2 have pointers with same value. But the pointers not point to same point in the PC memory!

The question remain: How can I share a memory block between applications?

Extense problem:
The code for prog1:
#include
int main()
{
char *p,str[]="here I am!";
FILE *fp;
p=str;
printf("%p %d\n%s\n",p,sizeof(p),p);
fp=fopen("address.bin","wb");
fwrite(&p,sizeof(char *), 1,fp);
fclose(fp);
while(0x01);
return(0);
};

The code for prog2:
#include
int main()
{
char *p;
FILE *fp;
fp=fopen("address.bin","rb");
fread(&p,sizeof(char *),1,fp);
fclose(fp);
printf("%p %d\n%s\n",p,sizeof(p),p);
return(0);
};

We expect that prog2 print out "here I am!".
But It not do!

ps.: excuse me by my bad english.

marcioh
Newbie Poster
1 post since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You