On Wed, May 10, 2017 at 10:30 PM, Rob Gaddi <rgaddi@highlandtechnology.invalid> wrote: > Sorry, but I'm just too proud of this. > > Given that you have: > > class RegisterLayout(ctypes.Structure): > ...yadayadayada... > > You can then: > > fh = os.open('/dev/devicethingy', os.O_RDWR) > mm = mmap.mmap(fh, ctypes.sizeof(RegisterLayout)) > registers = RegisterLayout.from_buffer(mm) > > And it just works. Behaves exactly the same way memory-mapping that struct > in C would. Sure the accesses take dict lookups, and that definitely slows > you down a bit. If you REALLY really needed that speed you'd be writing C. > But it works.
To clarify, the dict lookup here is to bind the CField data descriptor from the class dict. It isn't using the instance dict. -- https://mail.python.org/mailman/listinfo/python-list