Pickling ctypes pointer/array
Carlos Pita <[email protected]> Thu, 9 Jun 2016 14:49:03 -0300
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <CAELgYhdvDFPjho4PxQo_h8G_kedpeBYyYe_kLwBdQcfwP8JC+g@mail.gmail.com> |
Hi all, this question was triggered by the suggestion of Eryk in http://bugs.python.org/issue27274. Currently my way to go in order to pickle/unpickle the underlying array of a pointer is: ptr --cast--> array --copy--> bytes --dump--> pickle pickle --load--> bytes --(from_buffer_)copy --> array --cast--> ptr Eryk suggested a more concise way of achieving the same: ptr --string_at --> bytes --dump--> pickle pickle --load--> bytes --> create_string_buffer --> ptr (where I'm taking create_string_buffer as a kind of inverse of string_at). But this still makes a couple of copies. There are at least two obstacles on the way to pickling without copies: 1. Pickle is unable to serialize memoryviews. 2. It's not desirable to expose a pointer to the underlying memory of a bytes object, since bytes are supposed to be immutable. Now, what about bytearrays? If the underlying buffer of ctypes objects were get/settable as (views to) bytearrays no immutability constraint would be violated and we could move between python and c worlds without copying. Is something like that already possible? If not, is there an essential limitation preventing its implementation? Thank you in advance -- Carlos ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e _______________________________________________ ctypes-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ctypes-users