I am wondering if it is possible for the ctypes package to interface with mmap.
Currently, my module allocates a buffer (with create_string_buffer) and then passes that using byref to my libraries mylib.read function. This, as the name suggests, reads data into the buffer. I then call file.write(buf.raw) to write the data to disk. My benchmarks, however, show this to be far from optimal (time spent in file.write is time better spent in mylib.read).
I am therefore interested in knowing if ctypes can interoperate with mmap. Given an mmap.mmap instance and an offset how can I get a pointer (c_void_p) into the address space?
An
mmapobject “supports the writable buffer interface”, therefore you can use the from_buffer class method, which allctypesclasses have, with themmapinstance as the argument, to create actypesobject just like you want, i.e., sharing the memory (and therefore the underlying file) that themmapinstance has mapped. I imagine, in specific, that you’ll want a suitablectypesarray.