REPOST: Re: Efficient storage of floats

Martin von Loewis loewis at
Wed Dec 26 19:27:58 EST 2001

"Francois Petitjean" <littlejohn.75 at> 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

> 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


========= WAS CANCELLED BY =======:
From: Martin von Loewis <loewis at>
Newsgroups: comp.lang.python
Subject: cmsg cancel <j4adw5h5gx.fsf at>
Control: cancel <j4adw5h5gx.fsf at>
Date: Mon, 31 Dec 2001 03:18:33 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.j4adw5h5gx.fsf at>
X-Trace: 1009776204 27193 (31 Dec 2001 05:23:24 GMT)
X-Complaints-To: usenet at
NNTP-Posting-Date: Mon, 31 Dec 2001 05:23:24 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.

More information about the Python-list mailing list