How to share memory between applications?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 1
Reputation: marcioh is an unknown quantity at this point 
Solved Threads: 0
marcioh marcioh is offline Offline
Newbie Poster

How to share memory between applications?

 
-1
  #1
Nov 28th, 2004
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 <stdio.h>
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 <stdio.h>
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC