Re: Is it possible to get the Physical memory address of a variablein python?

Discussion in 'Python' started by Ognjen Bezanov, Nov 10, 2009.

  1. Hey,

    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
    language.

    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.

    Now what I've done so far is on the remote host I run python and set a
    variable as so:

    a = "foo"
    print a
    'foo'

    Then on the local host I run a python script that scans the entire RAM
    looking for the string "foo", and replaces it with the string "oof". I
    have had success with this method. Once it's done and I do "print a" on
    the remote host, I get "oof" as the variable value, so in theory it can
    work.

    Problem is that it's slow. Scanning 3GB of RAM every time you want to do
    this is not a good method. I thought that if I could get python to
    return the physical address of where the value of a variable is, then I
    can just jump to that address and write the data.

    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?

    Thanks!


    Ognjen
    Ognjen Bezanov, Nov 10, 2009
    #1
    1. Advertising

  2. Ognjen Bezanov

    Carl Banks Guest

    On Nov 10, 3:32 am, Ognjen Bezanov <> wrote:
    > Hey,
    >
    > 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
    > language.
    >
    > 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.


    [snip]

    >  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
    with ctypes.

    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.


    Carl Banks
    Carl Banks, Nov 10, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SJ

    MAC Address/Physical Address?

    SJ, Jan 7, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    501
  2. Bart Nessux

    Get Amount of Physical Memory

    Bart Nessux, May 24, 2004, in forum: Python
    Replies:
    2
    Views:
    310
    Helmut Jarausch
    May 26, 2004
  3. Krishna Sagiraju

    convert virtual address to physical address

    Krishna Sagiraju, Jul 10, 2004, in forum: C Programming
    Replies:
    3
    Views:
    1,196
    Malcolm
    Jul 10, 2004
  4. sushant

    virtual address or physical address?

    sushant, Feb 18, 2005, in forum: C Programming
    Replies:
    9
    Views:
    994
    CBFalconer
    Feb 18, 2005
  5. Ognjen Bezanov
    Replies:
    1
    Views:
    1,339
    Carl Banks
    Nov 10, 2009
Loading...

Share This Page