|
From: Kevin K. <ke...@re...> - 2008-01-17 01:29:47
|
Alexandre Ferrieux asks about the code in GetBignumFromObj:
> Now I'm having a hard time understanding this: what if the string rep
> is not NULL (for example if the bignum has just been printed) ? It
> would seem that in this case, the object is reset to a pure string,
> namely that representing the bignum. While if it was NULL (for example
> just after a bignum computation), the string rep is empty. Why that
> dichotomy ? And why touch the ptrAndLong ?
Unlike several other API's, the bignum API is designed in an effort
to minimize the amount of internal representation copying that goes
on. There are quite a few cases where a bignum object is unshared,
and where we know that it will be dismissed as soon as we're done
with it. For instance, in
set p [expr {($q + $r) * $s}]
the bignum that holds $q+$r is not needed once the multiplication
is done.
The path you have found is the path where the caller of GetBignumFromObj
is taking ownership of the bignum. We destroy the internal rep of
the object and give the bignum to the caller, who takes responsibility
for freeing it.
There is a corresponding path in Tcl_NewBignumObj for the caller to
transfer ownership of the bignum to the object; in this path, the
bignum in the caller is zeroed out.
--
73 de ke9tv/2, Kevin
|