Odd behaviour of ResizableWhateverArray PMC's

Bob Rogers rogers-perl6 at rgrjr.dyndns.org
Fri Oct 9 19:38:04 UTC 2009


   From: chromatic <chromatic at wgz.org>
   Date: Thu, 8 Oct 2009 23:50:17 -0700

   On Thursday 08 October 2009 23:46:47 Christoph Otto wrote:

   > I guess it kinda makes sense to initialize the complex types (STRING and
   > PMC) and leave garbage in the primitive types (Integer and Float), but it
   > strikes me a premature optimization and hardly ever DTRT.  Since it
   > involves changing the smallest amount of code, I'd vote for making RFA and
   > RIA initialize empty elements upon resizing.

   I mostly agree, but remember that we may face the semi-predicate
   problem here.  How can we tell the difference between an empty
   element and an element containing 0 or 0.0?

   That's not an argument against initializing empty elements -- merely a 
   suggestion for consideration.

   -- c

It's easy for an application that never assigns zeros, which is not
uncommon.  On the other hand, you can't ever tell the difference between
an empty element and an element containing a random value, with any
certainty, for any application.

   Indeed, I can't imagine a real use case for leaving the values
random.  Either you would have to ensure that you (a) store into all
elements below a certain maximum, (b) keep track of the indices you did
store into, or (c) guarantee that you never look at the unstored ones.
Case (c) might be plausible, but case (a) seems rare, and implementing
case (b) would require a separate (initialized!) array or a hash.  And
if you use a hash, why bother with the array?

   And if you expect the indices to be sufficiently sparse, then using a
hash may give you better performance anyway, even if unassigned elements
of the array are left uninitialized.

   However, one *could* argue for a creation-time option to control the
default value, e.g. setting it to -1 for storing 0-based indices in the
array.  That might be something to consider if a redesign of array types
is in the works.

					-- Bob Rogers (being random)
					   http://www.rgrjr.com/


More information about the parrot-dev mailing list