473,289 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Reading memory-adresses from files

Hello NG,

is fscanf capable of reading a memory adress from a file? I tried to
find the right format-parameter, but my code doesn't seem to work...

Regards,
Sebastian

----cut-----
int i=120;
int *a;
FILE *Outfile;
if ((Outfile = fopen("tst.dat","w"))== NULL) //open
{
if ((Outfile = fopen("tst.dat","w+"))==NULL) //create
{
printf("Error opening file\n");
exit();
}
}
printf("%p\n",&i);

fprintf(Outfile,"%p\n",&i);
fclose(Outfile);
Outfile = fopen("tst.dat","r");

fscanf(Outfile,"%p",a);
fclose(Outfile);
printf("%p",a);
----cut-------
Jul 22 '05 #1
4 2073
Sebastian Becker wrote:
is fscanf capable of reading a memory adress from a file? I tried to
find the right format-parameter, but my code doesn't seem to work...


Any number can mean whatever you make it mean. For example, something
like 0x10000000 on Windows may mean the address from which a DLL is
loaded. It may actually be a valid address once you read that number
from a file and convert into an address.

When a program runs, objects in it are located at some addresses that
can be converted to numbers (long is usually large enough to represent
any object pointer value). While the program is running you can write
those values to a file and later (while the program is still running)
retrieve them from that file and use after converting back to pointers.
It is possible that those addresses will stay valid during the run of
the program, and you can actually know that yourself: pointers' lives
are well defined.

When the program exits, finishes, the memory it used to occupy and use
for the objects, is usually freed. Nothing can guarantee that the next
run of the same program will mean that the same objects are located at
the same memory addresses, generally.

So, the answer to your question is probably: while it is possible for
your program to store and retrieve addresses in/from files, there is no
much sense in doing that.

V
Jul 22 '05 #2
> It may actually be a valid address once you read that number
from a file and convert into an address.
This is exactly what I want to do, but my code doesn't work.

I want use a preemptiv multitasking "core" [1] to run 3-4 programs at
the same time. For IPC purposes there is a shared memory needed. Now, my
idea was to initialize variables in the first program (which will be
running the whole time) and hand over the adresses to the other
programs. Doing this the CPU can remain in real-mode.
So, the answer to your question is probably: while it is possible for
your program to store and retrieve addresses in/from files, there is no
much sense in doing that.


So, how do you program this retrival of pointers from files?

Thanks, Sebastian
[1] http://www.shamrock.de/dostools.htm#multitasking - unfortunately
only in german

mt.com [Parameters: filenames of the tasks (exe)]
- runs in real-mode
- preemptive multi-tasking
- tasks are switched by a reprogrammed keyboard interrupt
Jul 22 '05 #3
"Sebastian Becker" <sb*******@gmx.net> wrote...
It may actually be a valid address once you read that number
from a file and convert into an address.


This is exactly what I want to do, but my code doesn't work.

I want use a preemptiv multitasking "core" [1] to run 3-4 programs at the
same time. For IPC purposes there is a shared memory needed. Now, my idea
was to initialize variables in the first program (which will be running
the whole time) and hand over the adresses to the other programs. Doing
this the CPU can remain in real-mode.
So, the answer to your question is probably: while it is possible for
your program to store and retrieve addresses in/from files, there is no
much sense in doing that.


So, how do you program this retrival of pointers from files?


Just like I said, convert them to integers when printing out and then
read them as integers and convert from integers to pointers after they
have been read.

V
Jul 22 '05 #4
> Just like I said, convert them to integers when printing out and then
read them as integers and convert from integers to pointers after they
have been read.


Thanks, works fine now.
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: guillaume | last post by:
I have to read and process a large ASCII file containing a mesh : a list of points and triangles. The file is 100 MBytes. I first tried to do it in memory but I think I am running out of memory...
6
by: Kevin T. Ryan | last post by:
Hi All - I'm not sure, but I'm wondering if this is a bug, or maybe (more likely) I'm misunderstanding something...see below: >>> f = open('testfile', 'w') >>> f.write('kevin\n') >>>...
4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
4
by: Yodai | last post by:
Hi all.. I'm trying to program an application for an emmbedded sistem where an external processor introduces data into my RAM. The thing is some if the data I have to pick up is written in...
7
by: eriwik | last post by:
Hi, I'm working on a small application which processes PNG-images and need to read parts of them into structures and/or variables and I was wondering what assumptions one can make about how the...
4
by: Henk | last post by:
Hi, I am new to the c-programming language and at the moment I am struggling with the following: I want to read a file using fread() and then put it in to memory. I want to use a (singel)...
6
by: Gerald Maher | last post by:
Hi Reading in XML file using C#, changing elements and saving back to the file, how can i do that ? I want to be able to read an XML file and read out Elements. for example <name>Tom</tom> ...
0
by: Einar Høst | last post by:
Hi, I'm reading data from a text file, and having read a bit on performance and memory, I'm wondering how it could be done in the fastest, most frugal way. The data comes in messages, one per...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
19
by: Hapa | last post by:
Does only reading (never writing) of a variable need thread synchronisation? Thanks for help? PS. Anybody knows a Visual C++ news group?
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.