Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

creating uneeded instances #4

Open
jsbueno opened this issue Nov 11, 2017 · 2 comments
Open

creating uneeded instances #4

jsbueno opened this issue Nov 11, 2017 · 2 comments

Comments

@jsbueno
Copy link

jsbueno commented Nov 11, 2017

[ctypes.POINTER(Point)])

This calling of the wrapper functions and assignment to the instance on every new point instantiation just looks bad. It is not that bad, as the wrapped functions are not new objects, but it remakes the assignment to the unique func in the ctypes wrapper for the library (although it would still have a major impact would one write actual Python code dealing with a couple hundred of Point instances)

I'd suggest just making the wrap call once, on top level code, would be much more elegant here:

class Point(...):
    ...
    def move(self):
         Point._move_point_func(self)

# These assignments must be after class body, due to the needed referenc  to the class itself.
 Point._move_point_func = wrap_function(lib, 'move_point', None, [Point])
...

(I am not sure if the functions wrapped by ctypes have a proper __get__. If they have, you might not even need the intermediate move method)

@jima80525
Copy link
Owner

Thanks! I'll play around with that when I get a minute or two. I REALLY appreciate that suggestion! I learned a great deal figuring out this demo and I'm glad to get to learn some more from it!
I'll leave this open until I work through your suggestion.

Thank you!

@jima80525
Copy link
Owner

I created a pull request if you've got a few minutes. I think this is what you were getting at.
#6

Also, I didn't quite follow your final comment. Is it along the lines of hooking into the getattr function of the Line class, looking up the attributes of the library and then automatically calling an existing function?

I might play with that next.

Thanks again for your ideas! I really appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants