Hi Robert, On Mon, 26 May 2003 17:18:35 +0900 "Robert Klemme" <bob.news / gmx.net> wrote: > > I have used hash in my ruby program. It worked fine. However, I found > > that the memory consumed by a hash is tremendous. While the hash file is > > stored on disk (using pstore) it is merely 100-200KB, but in memory, it > > consumes apporximately 5-10 Megabytes! I don't know if it is related to > > the cache algorithm used by ruby? > > How did you measure this? Is there a way to know the amount of memory > used of an object graph? I have no good way to measure this. What I did is to watch the *total* memory required by the program, with or without the hash. I don't know if there is a way to do what you mentioned. May be some ruby experts know? > > It's a typical tradeoff: you can't have both - space efficiency AND > minimal memory consumption. If you *have* to keep memory consumption low > I think there is a tree implementation in the RAA. Another option would > be to use an Array, keep that sorted and implement (or use) a binary > search, which gives quite similar fetch performance as a tree. Insert > might or might not be slower. In my program lookup is very freqent, but update is rare. I tried using Array.include? , but it seems is using seqential search, not binary. The performance is unbearable. Does anyone know if ruby's internal Array.include? is using binary search or not? Thanks! Shannon