Efficient storage of floats

Martin von Loewis loewis at informatik.hu-berlin.de
Wed Dec 26 19:27:58 EST 2001


"Francois Petitjean" <littlejohn.75 at free.fr> writes:

> Is it possible to have a quantitative assessment of the overhead of the two
> methods 1(list) or 2(array)? (overhead in memory footprint or CPU cycles).

Getting the overhead in memory consumption is possible, but it is
quite time consuming (you'll have to consider malloc overhead as
well); see my earlier articles on "size of objects" for examples. It
is well possible that the list version consumes five times or more than
memory than the array version.

On CPU cycles, you get additional indirections with the lists, but
this is difficult to estimate - that is best done through bench
marking.

> And is it interesting to preinitialize the structure? The number of
> points is typically 800*2 (for symmetry) that is say up to 8000
> floats.

Depends on how often you destroy and recreate them, compared to
actually using the data. For a list, pre-allocation is quite
pointless, since the list will over-allocate anyway. For an array, it
may be reasonable.

BTW, pre-allocating [(0.0, 0.0, 0.0)*800] is worse than pre-allocating
[None*800]. All 800 references will point to the same object in each
case, only that "creating" None is more efficient than creating the
tuple.

Regards,
Martin




More information about the Python-list mailing list