I cannot figure how to get the virtual address of the standard mmap objects in Python (from the mmap module). The documented methods only seem to access the memory as array of bytes or as character strings.
But I need to access the mmap'ped memory by precisely 2 or 4 bytes at once - because this memory in my application is mapped to hardware registers (think /dev/mem or GPIO or such). Accessing memory in this way is possible with ctypes module - but for this I need the pointer - or virtual address - of the mapping.
Currently I overcome this by using the native open() and mmap() functions from libc (thanks to the same ctypes) but would rather not.
Why the mmap module won't provide easy way to get the memory address? Hope I'm missing something obvious...
-- dd
Here is a more complete code that I need get working, with Python 2.7, on Linux:
Again, I should be missing something obvious as I'm new to Python
-- dd
Traceback:
mmap
objects support the writable buffer interface, so you can use thefrom_buffer
class method thatctypes
classes have with themmap
object as an argument to get actypes
object that shares the memory of themmap
file.