[DGD]Resources used by sparse arrays
Erwin Harte
harte at xs4all.nl
Fri Dec 15 21:53:33 CET 2000
On Fri, Dec 15, 2000 at 01:43:18PM -0500, Cathy Willey wrote:
> In the system I'm designing, a situation has come up that can be
> resolved in one of two ways: data can be stored in either a very sparse
> string array (it might have 45 elements, with data in perhaps seven of
> them), or the same data can be stored in two arrays: one with the
> 'index' where the data would have gone in the sparse array, and one with
> the actual data. (A mapping won't work nicely due to what I'm doing with
> it - trust me on this one. :) )
If you say so. :)
> My questions to the more knowledgeable types are these: first, is more
> memory going to be used by that array with 38 empty elements and seven
> strings in it, or by an array of seven integers plus an array of seven
> strings? Second, would the situation change if the arrays were smaller
> (say, 5 out of 22 elements filled, or two five-element arrays) or more
> densely packed (say, 15 out of those 45 elements filled)?
The 45 element array with 7 strings will take more memory than the
pair of 7 element arrays.
In each case you'd have the same memory requirements for the strings,
so the size of the (one, or two) arrays is really what counts.
Storing an integer in an array has no extra overhead compared to having
the array being allocated in the first place, so they can be ignored.
Of course, now that I've written this I'm starting to doubt all my
memories, so I hope that someone will correct me if I'm way off. :-)
Erwin.
--
Erwin Harte : `Don't mind Erwin, he gets crabby. :)'
harte at xs4all.nl : -- Par Winzell <zell at skotos.net>
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list