Is it possible to get the Physical memory address of a variable in python?
pavlovevidence at gmail.com
Wed Nov 11 00:38:24 CET 2009
On Nov 10, 3:32 am, Ognjen Bezanov <Ogn... at mailshack.com> wrote:
> Thanks for all the responses guys. In hindsight I probably should have
> explained why on earth I'd need the physical address from an interpreted
> I'm trying to see if there is any way I can make Python share data
> between two hosts using DMA transfers over a firewire connection, so
> avoiding the need for another layer on top such as IPv4 + Python sockets.
> Thanks to some old python bindings which I updated to python 2.6, I can
> read any write to the RAM of any firewire connected host within python.
> Because it uses DMA (the cpu is not involved in this at all), I can only
> specify a physical address within the 4GB ram limit to read from and
> write to.
> From what I've been told so far, it's not possible to do this without
> some OS-specific (Linux in this case) syscall. Is this correct?
What you'd normally need to do it to use system calls to allocate a
DMA-able memory buffer, then copy contents of your Python object
(which you get at using buffer protocol) to this buffer, then initiate
the DMA transfer. At this point it probably would be easier to just
write a C-extension to do that, but I see no reason it can't be done
However, I'm not sure how that would interact with your pre-existing
module. I'd expect a module that does DMA to take care of physical
address mapping itself, you just pass it a logical address, or an
object that supports buffer protocol, and it does the rest.
It seems just getting a physical address and starting a DMA transfer
from it is prone to danger if memory pages are discontiguous (and they
often are), but maybe OSes these days can handle that automatically.
More information about the Python-list