Originally posted by ruttopia:
<STRONG>How do iTunes and iPhoto keep track of all their items and do it so well? Is this just a big array or do they use some sort of database mechanism? I posted this a few months ago and no one really helped so I thought I'd try it one more time. I'm just curious ...
I'm assuming they just store everything in a big array since you won't have more than a few thousand items ...?</STRONG>
I don't pretend to know anything about the internals of either app, but I suspect that the backing store is a little more complex than an array, but very similar conceptually. If you notice one thing about the way both apps store things, it's that they only have one level of embedding. That is, in iTunes you can't create a playlist in a playlist. So the data structure there probably isn't a tree, but maybe a big dictionary or something like it. iTunes and iPhoto only let you do sorting, there's no database-like querying available.
I'm sure each object, like a song or photo, is some custom class and then there are other, higher-level container classes (like Playlist or PhotoAlbum) which know how to represent their contents in a flexible manner. In Cocoa, it's pretty easy to write out representations of complex classes to disk (serialization), but it's not as easy in Carbon (since it's a straight C interface).
Since one is written in Carbon and C++ and the other in Cocoa and Objective C, the structures they use are probably very different, but the concepts are pretty similar.