Advantage:
Disadvantage:
Advantages:
Disadvantage:
Consider these two functions:
double *get_array_leaky(const int len)
{
double *array = new double[len];
for (int i = 0; i < len; i++)
{
array[i] = (double)i;
}
return array;
}
void get_array_safe(const int len, double array[])
{
for (int i = 0; i < len; i++)
{
array[i] = (double)i;
}
}
How can we use the second one?
from cffi import FFI
def get_array_safe(length):
ffi = FFI()
lib = ffi.dlopen(...)
array = ffi.new("double[]", length)
lib.get_array_safe(length, array)
return array
Allocate API arrays client-side.
Write a thin Python layer around them.