Page 1 of 1
Analyzing pointers
Posted: Tue Aug 29, 2023 6:47 am
by Tuoma
I have a list of pointers, in my case I get them from
Code: Select all
myvec = [x._ref_concentration for x in mySpecies.nodes]
When I write "print(myvec[0])" I get "<pointer to hoc scalar 0>", but I'd like to know more about it and I don't know how.
Is there a way to know what are the addresses the pointers are pointing to? I'm ultimately trying to find what's causing my seg fault and this could help.
Re: Analyzing pointers
Posted: Wed Aug 30, 2023 2:23 pm
by hines
I'm sorry to say that in NEURON version 8 and before , the interpreters do not store the information used to determine the address. And in the internal implementation the only way to know what a pointer was pointing to was to search all internal data structures. This, of course, made it very inconvenient when we reorganized memory layout for cache efficiency. Version 9, now uses data handles as much as possible in place of pointers. For example
Code: Select all
$ cat temp.py
from neuron import h
slist = [h.Section(name="s%d"%i) for i in range(5)]
for s in slist:
s.nseg = 3
s.insert("hh")
slist[2](.5).hh.gnabar = 0.2
ref = slist[2](.5).hh._ref_gnabar
assert ref[0] == 0.2
print(ref)
gives
Code: Select all
$ python3 -i temp.py
data_handle<double>{cont=hh gnabar row=7/15 val=0.2}
and if I
Code: Select all
>>> slist[0] = None
>>> ref
data_handle<double>{cont=hh gnabar row=7/12 val=0.2}
Unfortunately, in version 9 we have not yet extended the data handle approach to rxd. So far in version 9, we still use raw pointers to rxd data so that
Code: Select all
>>> xref = NT.nodes(h.spine[0])(0.5)[0]._ref_concentration
>>> xref
data_handle<double>{raw=0x559b6797d040}
So for now, all you can do is create a dict of the _ref instances you create and associate them with a string of how they were created.