Re: [GEN] multiple pointers

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Cense

I replied but perhaps what I suggested was dumb.

You can't get pointers to your Euphoria atoms. You need to allocate memory
to hold the values you require. You then save a pointer to the memory (which
will need to be a certain size to hold the value(s) you need).

(You probably knew all this anyway!)

I assume "list" is a memory location that holds a pointer to memory?


I can't see why it would seg fault on a peek but I dont *think* that you
will get what you are looking for pointer wise if you use a simple peek
to get at your pointer.

I think peek will only return one byte of the address you require.

When you do

ptr = peek( list ) -- Seg Fault happens here

you might only be getting the first byte of the pointer because peek only
returns a single byte value from the specified location. If that location
holds
a 32-bit pointer that you also want to peek then you won't get the whole
pointer.

When you then use that (incorrect?) pointer to get at your array of char's
I *think* you will be peeking the totally wrong location.

Perhaps you should try peek4u instead to get the whole pointer value.


perhaps something like (untested code...sorry Jiri!)........

atom list, ptr_to_list
sequence all_values_in_list

ptr_to_list = allocate(4) -- 32-bit location to hold location of list
list = allocate(50) -- 50 byte sized values (chars?)

poke4(ptr_to_list, list) -- ptr_to_list now contains the location of the
list

-- to get at the list using your pointer to the list
ptr = peek4u(ptr_to_list) -- should give us the pointer to the list
all_values_in_list  = peek({ptr, 50}) -- read all values in the list into a
sequence


Could you let us know what you are working on?

If I have got this totally wrong please let me know.

All the best

Mark

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu