On Freitag, 6. Januar 2017 00:28:37 Hans-Peter Jansen wrote: > Hi Eryk, > > This is exactly, what I was after: > > @contextmanager > def cstructmap(cstruct, mm, offset = 0): > # resize the mmap (and backing file), if structure exceeds mmap size > # mmap size must be aligned to mmap.PAGESIZE > cssize = ctypes.sizeof(cstruct) > if offset + cssize > mm.size(): > newsize = align(offset + cssize, mmap.PAGESIZE) > mm.resize(newsize) > cmap = cstruct.from_buffer(mm, offset) > try: > yield cmap > finally: > for mv in cmap._objects.values(): if isinstance(mv, memoryview): mv.release()
It happens, that _objects contain other objects as well... Cheers, Pete _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com