[Python-Dev] Caching float(0.0)
Kristján V. Jónsson
kristjan at ccpgames.com
Sat Sep 30 13:20:07 CEST 2006
Well, a lot of extension code, like ours use PyFloat_FromDouble(foo); This can be from vectors and stuff. Very often these are values from a database. Integral float values are very common in such case and id didn't occur to me that they weren't being reused, at least for small values.
Also, a lot of arithmetic involving floats is expected to end in integers, like computing some index from a float value. Integers get promoted to floats when touched by them, as you know.
Anyway, I now precreate integral values from -10 to 10 with great effect. The cost is minimal, the benefit great.
From: python-dev-bounces+kristjan=ccpgames.com at python.org [mailto:python-dev-bounces+kristjan=ccpgames.com at python.org] On Behalf Of "Martin v. Löwis"
Sent: 30. september 2006 08:48
To: Bob Ippolito
Cc: python-dev at python.org
Subject: Re: [Python-Dev] Caching float(0.0)
Bob Ippolito schrieb:
> My guess is that people do have this problem, they just don't know
> where that memory has gone. I know I don't count objects unless I have
> a process that's leaking memory or it grows so big that I notice (by
> swapping or chance).
Right. Although I do wonder what kind of software people write to run
into this problem. As Guido points out, the numbers must be the result
from some computation, or created by an extension module by different
means. If people have many *simultaneous* copies of 0.0, I would expect
there is something else really wrong with the data structures or
algorithms they use.
Python-Dev mailing list
Python-Dev at python.org
More information about the Python-Dev