is None or == None ?

Rami Chowdhury rami.chowdhury at gmail.com
Fri Nov 6 14:28:15 EST 2009


On Fri, 06 Nov 2009 09:28:08 -0800, Alf P. Steinbach <alfps at start.no>  
wrote:

> * Rami Chowdhury:
>> On Fri, 06 Nov 2009 08:54:53 -0800, Alf P. Steinbach <alfps at start.no>  
>> wrote:
>>
>>> But wow. That's pretty hare-brained: dynamic allocation for every  
>>> stored value outside the cache range, needless extra indirection for  
>>> every operation.
>>>
>>  Perhaps I'm not understanding this thread at all but how is dynamic  
>> allocation hare-brained, and what's the 'needless extra indirection'?
>
> Dynamic allocation isn't hare-brained, but doing it for every stored  
> integer value outside a very small range is, because dynamic allocation  
> is (relatively speaking, in the context of integer operations) very  
> costly even with a (relatively speaking, in the context of general  
> dynamic allocation) very efficient small-objects allocator - here  
> talking order(s) of magnitude.

Well, sure, it may seem that way. But how large a cache would you want to  
preallocate? I can't see the average Python program needing to use the  
integers from -10000 to 10000, for instance. In my (admittedly limited)  
experience Python programs typically deal with rather more complex objects  
than plain integers.

>    int intValueOf( Object const& o )
>    {
>        if( o.type_id != int_type_id ) { throw TypeError(); }
>        return static_cast<IntType*>( o.p )->value;    // Extra  
> indirection
>    }

If a large cache were created and maintained, would it not be equally  
indirect to check for the presence of a value in the cache, and return  
that value if it's present?

> creating that value then involves a dynamic allocation.

Creating which value, sorry -- the type object?


-- 
Rami Chowdhury
"Never attribute to malice that which can be attributed to stupidity" --  
Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)



More information about the Python-list mailing list