How to use a contiguous memory location of n bytes in python

Discussion in 'Python' started by chachi, Nov 14, 2008.

  1. chachi

    chachi Guest

    Hi,

    I want to know how to instantiate a data structure which has n bytes
    (given by me) and is internally stored in a contiguous fashion. I know
    list is not implemented like this, so I am in a fix. There seems to be
    a buffer object available, but haven't seen it being used anywhere.
    Does anyone know how to use Buffer? Say I want to write some data onto
    the buffer and then write the contents of the entire buffer to a file
    (without making a new string, but lets first get the buffer issue out
    of the way), how do I do it?



    Thanks,
    ssg
     
    chachi, Nov 14, 2008
    #1
    1. Advertising

  2. chachi

    Guest

    chachi:
    > I want to know how to instantiate a data structure which has n bytes
    > (given by me) and is internally stored in a contiguous fashion.


    array.array("B", ...) may be fit for you. You can also use a numpy
    array of bytes.

    Bye,
    bearophile
     
    , Nov 14, 2008
    #2
    1. Advertising

  3. chachi

    Aaron Brady Guest

    On Nov 13, 6:40 pm, wrote:
    > chachi:
    >
    > > I want to know how to instantiate a data structure which has n bytes
    > > (given by me) and is internally stored in a contiguous fashion.

    >
    > array.array("B", ...) may be fit for you. You can also use a numpy
    > array of bytes.
    >
    > Bye,
    > bearophile


    Also, there is the 'mmap' module.
     
    Aaron Brady, Nov 14, 2008
    #3
    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. panbru

    Contiguous memory blocks

    panbru, Aug 5, 2003, in forum: Python
    Replies:
    0
    Views:
    369
    panbru
    Aug 5, 2003
  2. Olumide
    Replies:
    9
    Views:
    2,039
    Dan Pop
    Nov 30, 2004
  3. Gary Kuehn
    Replies:
    2
    Views:
    495
    Gary Kuehn
    Jul 19, 2005
  4. Martin
    Replies:
    5
    Views:
    381
    Martin
    Feb 11, 2008
  5. Ronald

    Memory leak? Private Bytes/Virtual Bytes

    Ronald, Mar 7, 2005, in forum: ASP General
    Replies:
    3
    Views:
    569
    Pat [MSFT]
    Mar 9, 2005
Loading...

Share This Page