Luka
Luka

Reputation: 1

allocating memory for list - Python

Using the C API for Python, how can I create a list and allocate some memory for it? For example, I tried this code to make a list that will store 4 elements, but I get an error saying that it can't assign to operator:

char *buf1 = int* PyMem_New(int, 4)

Upvotes: -1

Views: 2030

Answers (2)

Kurt Telep
Kurt Telep

Reputation: 729

I believe buf1 needs to be a pointer.

char *buf1 = PyMem_New(int, 4);

Upvotes: -1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799230

PyList_New() allows you to specify an initial size in the single mandatory argument. Don't forget to actually set the items with PyList_SetItem() before using the list in Python code though.

Upvotes: 1

Related Questions