Let’s say I have a 10 element array:
from ctypes import *
arr = c_float * 10
, and I’d like to shrink it to 5 elements. I tried doing something like this:
resize(arr, sizeof(c_float) * 5)
arr = (c_float * 5).from_address(addressof(arr))
But I get a ValueError: minimum size is XXX exception meaning that I can’t shrink the memory, only grow it. If I really want, is it possible to overcome this limitation with a clever hack?
This seems to work just fine:
EDIT: This doesn’t actually resize the original list though, and
addressof(a1)will equaladdressof(a2), so the unused bits of the list linger in memory…