Pointer to memory

M

MarkY

How does on "point" a pointer at a specific memory address? I have a
program where I've malloc'd some memory and need to move around and
make changes. I know I can move a pointer in the malloc'd storage by
incrementing a pointer. However, in this malloc'd storage, I have
stored addresses of other locations and would like to "jump" from one
memory location to another based on what I find in certain memory
ranges. Don't worry, I've taken care of word aligning, etc. etc.

So to recap:
1. I have malloc'd storage
2. I have written blocks of data into this storage (I know it's there
because I can traverse the entire storage and output the information
alas, by incrementing the pointer)
3. I need to jump from run location to another based on some of the
data I've added.


Thanks,
Mark
 
A

Andreas Kahari

MarkY wrote: said:
So to recap:
1. I have malloc'd storage
2. I have written blocks of data into this storage (I know it's there
because I can traverse the entire storage and output the information
alas, by incrementing the pointer)
3. I need to jump from run location to another based on some of the
data I've added.


Is this very different from

thing = memoryarray[memoryarray];

or

thing = memoryarray[(int) memoryarray];

or possibly

thing = memoryarray[converttoindex(&memoryarray)];

(where converttoindex() returns an int computed from the data
pointed to by the argument) ?


You're allowed to do that, but you're responsible for making
sure you store the right things at the right places with the
right types.
 
M

MarkY

Andreas Kahari said:
Is this very different from

thing = memoryarray[memoryarray];

or

thing = memoryarray[(int) memoryarray];

or possibly

thing = memoryarray[converttoindex(&memoryarray)];

(where converttoindex() returns an int computed from the data
pointed to by the argument) ?


You're allowed to do that, but you're responsible for making
sure you store the right things at the right places with the
right types.


Thanks Andreas. I was able to use a slightly modified version of Option 3.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top