[Tutor] __slots__

Alan Gauld alan.gauld at freenet.co.uk
Thu Oct 13 11:13:47 CEST 2005


> > As a matter of interest why do you need so many in RAM at once?
>
> I'm creating an object for each header (for want of a better word.) A
> song is described by an object with several children objects, each one
> has certain attributes. 

OK, But you only need the song object group to manipulate the song right?
Normally you only manipulate one song at a time, so instantiate the song 
objects only as you need them and delete when done.

> database object (contains controls, songs, podcasts, playlists etc)
> composite objects (each object is composite of several base objects)
> base objects (objects derived from binary data)

Thats all OK so far.

> (This is really rough). So, 15,000 songs equates to 1500 playlists
> (including smart playlists) , and 180,000 objects/headers.

Yes, but why do you need them all in memory at the same time? 
The only case I'd see that being necessary was if you were trying 
to do a bulk update of a single attribute across all songs? 
(And even then you could batch it internally))

> Now, I've thought about doing this various ways, but creating a
> coherent and usable data structure while keeping the structure of the
> binary file easily recreatable is what I'm after.

Can't you read the data from the binary file as needed?
For example build a table of object ids versus file locations 
and then use seek() to go to an object and load it from file 
on demand?

> So, in doing so, I end up with a whole lot of objects, but it's a
> whole lot of objects I can easily use.

Easy to use but hoggingmemory. If you make the init method 
read the file then instantiating on demand becomes pretty easy too.

> PS Can you recommend a decent place for a hobbyist to learn about late
> evaluation etc?

Its just the kind of stuff described above. Instead of ac tually 
holding the objects hold a reference to the class and the id(a tuple?), 
then when you actually need the object instantiate it and let the 
constructor fetch the data on demand. That way you only need the 
top level objects in RAM - the current playlist or song selection say...

HTH,

Alan G.


More information about the Tutor mailing list