Re: [PyOpenGL-Users] Pointer functions copying memory.
Brought to you by:
mcfletch
From: Mike C. F. <mcf...@ro...> - 2003-02-04 21:31:11
|
Hmm, lots of users don't really care if there's a little inefficiency if it means they can get on with their lives (premature optimisation and all that), they just want to see if what they're doing is doing what it's supposed to, and having an error raised for what is essentially a Numeric Python internal bookkeeping difficulty would mean their (perfectly functional as-of-now) code just won't work. A warning might be possible, but even then, it seems a bit much. BTW, Here's a function that does the work of converting any given array to a contiguous Numeric Python array: try: import Numeric except ImportError: def contiguous( source ): """Place-holder for contiguous-array function, just returns argument This is only visible if Numeric Python is not installed """ return source else: def contiguous( source, typecode=None ): """Return source as a contiguous Numeric Python array""" if isinstance( source, Numeric.ArrayType): if source.iscontiguous() and (typecode is None or typecode==source.typecode()): return source else: return Numeric.array(source,typecode or source.typecode()) elif typecode: return Numeric.array( source, typecode ) else: return Numeric.array( source ) I'm considering adding that to OpenGL.GL.__init__.py . But would appreciate feedback regarding it first (particularly whether it's solving the problems with speed that gabor was noticing). It should be possible to simply call contiguous before storing your arrays and have no copying overhead imposed (as long as the data-types for array and pointer match, of course). I'll add notes to this affect to the docs as well if we go this route. I had considered having the gl*Pointer functions _return_ the contiguous array, but I don't like messing with the OpenGL API just to deal with a quirk of Numeric. Enjoy all, Mike Shane Holloway (Techgame) wrote: > I would prefer that PyOpenGL raise an exception instead of copying > memory. Providing a continious Numeric array is the responsibility of > the calling code, in my eyes, as the helpful copying is usually not > wanted in the longer term. It would also be important to give > examples in the documentation of how to restructure the Numeric object > to make the call work as intended. > > Thoughts? > > I tryed implementing this, but got quickly lost in the SWIG macros. > Made me run back to python ;) > > -Shane Holloway _______________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://members.rogers.com/mcfletch/ |