944,020 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2979
  • C RSS
Nov 28th, 2004
-1

How to share memory between applications?

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
marcioh is offline Offline
1 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: help on sorting...please...
Next Thread in C Forum Timeline: help writing a grep program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC