[Python-Dev] [Python-checkins] Who are the decimal volunteers? Re: cpython: Resize the coefficient to MPD_MINALLOC also if the requested size is below
stefan at bytereef.org
Tue Apr 10 00:06:23 CEST 2012
Jim Jewett <jimjjewett at gmail.com> wrote:
> Why is there any need for MPD_MINALLOC at all for (immutable) numbers?
> I suspect that will involve fleshing out some of the memory management
> issues around dynamic decimals, as touched on here:
"In order to avoid frequent resizing operations, the global variable
MPD_MINALLOC guarantees a minimum amount of allocated words for the
coefficient of each mpd_t. [...]"
So the rationale is to avoid resizing operations. The mpd_t data type
is not immutable -- I suspect no high speed library for arbitrary
precision arithmetic has an immutable data type.
PyDecObjects are immutable, but they have to be initialized at
some point. The mpd_t struct is part of a PyDecObject and is
in the position of the result operand during initialization.
All operations in _decimal.c follow the same scheme:
/* dec contains an mpd_t with MPD_MINALLOC words. */
dec = dec_alloc();
/* Initialization by a libmpdec function. MPD() is the
accessor macro for the mpd_t. */
mpd_func(MPD(dec), x, y, ...);
/* From here on dec is immutable */
More information about the Python-Dev