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

Adam Langley alangley at gmail.com
Wed Jun 8 20:16:47 CEST 2005


On 6/8/05, Chris Lambacher <lambacck at gmail.com> 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 = <unsigned char *> PyString_AsString(temp_string)

That's one way to do it. But it looks like you just want an area of
memory so why not:

cdef extern from "stdlib.h":
  ctypedef unsigned long size_t
  void *malloc(size_t size)
  void free(void *mem)

?

AGL

-- 
Adam Langley                                      agl at imperialviolet.org
http://www.imperialviolet.org                       (+44) (0)7906 332512
PGP: 9113   256A   CC0F   71A6   4C84   5087   CDA5   52DF   2CB6   3D60



More information about the Pyrex mailing list