Re: [Pyrex] Allocating an array.array of a specific length in pyrex

2005-06-08 Thread Chris Lambacher
And we have a winner. For reference the final code is below. Thanks for your help, -Chris import array cdef extern from "Python.h": int PyObject_AsWriteBuffer(object obj, void **buffer, int *buffer_len) int PyObject_AsReadBuffer(object obj, void **buffer, int *buffer_len) object PySt

Re: [Pyrex] Allocating an array.array of a specific length in pyrex

2005-06-08 Thread Chris Lambacher
I replaced: a = array.array('B', , [0] * (pixels * 2)) with: a = PyString_FromStringAndSize(NULL, pixels * 2) and got: C:\work\testing\plink_o_ip>python ycbycr.py Traceback (most recent call last): File "ycbycr.py", line 62, in ? ycbycr = image2ycbycr(im) File "ycbycr.py", line 38, in imag

Re: [Pyrex] Allocating an array.array of a specific length in pyrex

2005-06-08 Thread Chris Lambacher
The memory is not temporary, I am passing it out as an array, thus the malloc/free route will require double allocation(once for malloc/free, once for array.array). I am not using string because when I tried to pass the data in as string, pyrex complained about the conversion. However, I could pr

Re: [Pyrex] Allocating an array.array of a specific length in pyrex

2005-06-08 Thread Adam Langley
On 6/8/05, Chris Lambacher <[EMAIL PROTECTED]> wrote: > My question is, is there a better way to > allocate the memory for the array.array object than: > a = array.array('B', [0] * (pixels * 2)) cdef unsigned char *buffer temp_string = PyString_FromStringAndSize(NULL, length) buffer = PyStr

Allocating an array.array of a specific length in pyrex

2005-06-08 Thread Chris Lambacher
Hi, I have to do some data manipulation that needs to be fast. I had a generator approach (that was faster than a list approch) which was taking approximately 5 seconds to run both encode and decode. I have done a conversion to pyrex and have gotten it down to about 2 seconds to run both encode