ctypes pointers

G

Giorgos Giagas

Hi all,
I have started using ctypes and I am having some questions I can't
seem to find the answers to.

There is a structure referenced by a pointer in an other structure and
I want to see if it is one of the structures I have pointers to.
So what I think I need is a way to compare 2 pointer's memory
location. I can't find a way to do this. Pointer comparisons don't
work. Is there something else I should do?

The other thing is more of a curiosity... The documentation says that
I need to keep references to structures so they don't get freed is
this also true for structures returned as pointers? What about
structures that I cast to something else? I guess the largest of the
two casts gets freed like it should... can someone confirm this?
 
D

Diez B. Roggisch

Giorgos said:
Hi all,
I have started using ctypes and I am having some questions I can't
seem to find the answers to.

There is a structure referenced by a pointer in an other structure and
I want to see if it is one of the structures I have pointers to.
So what I think I need is a way to compare 2 pointer's memory
location. I can't find a way to do this. Pointer comparisons don't
work. Is there something else I should do?

Use addressof on the contents of your pointers.
The other thing is more of a curiosity... The documentation says that
I need to keep references to structures so they don't get freed is
this also true for structures returned as pointers? What about
structures that I cast to something else? I guess the largest of the
two casts gets freed like it should... can someone confirm this?

The one has nothing to do with the other.

If you create a struct and pass e.g. a pointer to it into a DLL, you need to
keep a reference, otherwise the struct will be deallocated and the pointer
is dangling.

If you have a pointer and cast it to some structure, you get a structure
object (in python) that points to a certain memory portion. But GCing that
object doesn't do anything to the memory location.

Diez
 
G

Giorgos Giagas

Use addressof on the contents of your pointers.

Thank you. I was looking for a pointer or structure property and
missed that.
The one has nothing to do with the other.

If you create a struct and pass e.g. a pointer to it into a DLL, you need to
keep a reference, otherwise the struct will be deallocated and the pointer
is dangling.

If you have a pointer and cast it to some structure, you get a structure
object (in python) that points to a certain memory portion. But GCing that
object doesn't do anything to the memory location.
That makes sence. I was confused about this thing...

Thanks a lot for the quick reply,
Giorgos
 

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

Forum statistics

Threads
474,294
Messages
2,571,508
Members
48,193
Latest member
DannyRober

Latest Threads

Top