StringIO and Berkley DB

Thomas Weholt thomas at cintra.no
Tue May 16 07:12:17 EDT 2000


Hi,

I want to store incredibly huge strings in a Berkley DB dictionary,
then read parts if it back using StringIO. The strings are acutally
tuples of integers, packed with the struct-module.

After I`ve stuffed the large string into the dictionary I point
StringIO to a value in the dictionary, then read a specified number of
bytes back. 

My question is: Do I need to have the entire string in memory before
the StringIO-module can use it? 

first :
db = # open Berkley DB
db['a_key'] = 'safdfasfdsafdsafdsafdasffdsafdsafasf' # for testing.
db.close()

The much later :

db = # open Berkley DB
f = StringIO.StringIO(db['a_key'])
ds = f.read(10)
f.close()
db.close()

Will the entire string be loaded into memory, or could I just point to
a location to read a number of bytes from? The goal of course is to
restrict memory usage and read a minimum to keep things fast, just
read what I need.

I use cStringIO in my code by the way, but I don`t think it has any
other method I could have used.

Thomas




More information about the Python-list mailing list