| | |
How to share memory between applications?
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 1
Reputation:
Solved Threads: 0
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.
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
- Memory usage (C++)
- How to share a database in LAN (C++)
- The Singularity Research Development Kit (Windows Software)
- Is shared video memory of laptop can support games? (Troubleshooting Dead Machines)
- Software Sharing (Windows NT / 2000 / XP)
- semaphores (C)
- threading in linux (C)
- multiple applications opening in XP (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: help on sorting...please...
- Next Thread: help writing a grep program
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list lists locate looping lowest matrix meter microsoft number oddnumber opendocumentformat openwebfoundation overwrite owf pdf pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi





