Jim Jewett <jimjjew...@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:
> http://www.bytereef.org/mpdecimal/doc/libmpdec/memory.html#static-and-dynamic-decimals

MPD_MINALLOC
------------

"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 */



Stefan Krah


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to