Open
Description
I'd like a better Cython primitive for allocating, filling, and converting from an H3 index array to a Cython memview
than our current approach of paired function calls to create_ptr
and create_mv
.
Example:
cpdef H3int[:] get_pentagon_indexes(int res):
cdef:
h3lib.H3Error err
check_res(res)
n = h3lib.pentagonCount()
ptr = create_ptr(n)
err = h3lib.getPentagons(res, ptr)
mv = create_mv(ptr, n)
return mv
Ideas:
- context manager (i'm not sure this can be done ergonomically)
- "memory manager" object that's in control of the size, allocation, type, and memory-view-creation of the memory
- avoid the need to mentally pair the memory and the memory size
- can have accessor methods or Python attributes to create/access the pointer and memory view
Other kinds of arrays
This pattern also doesn't cover when we have to allocate space for non-H3Index arrays.