[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] That was productive...



On Tue, Jan 18, 2000 at 07:03:33PM -0500, Chip Turner wrote:
> Ronald J Kimball <rjk@linguist.dartmouth.edu> writes:
> 
> > > Um, I'm talking about the internally allocated space for
> > > the array, not the publicly reported size.
> > > You know, the mechanism that allows arrays to be dynamically
> > > sized in perl.
> > > 
> > 
> > That would be a rather serious design error, wouldn't you say?  There's no
> > need to allocate space for an array if the space isn't being used for
> > anything.
> 
> Not at all.  Speed is the factor.  If you resize the array of SV
> pointers behind an array every time you extend the array, then you
> have a large amount of copying.  But if you increase it by more than
> one entry, then you have fewer copies of the data.  Many dynamic array
> algorithms/libraries do this.  Usually the next size is twice as large
> as the previous size.  This results in temporarily unused memory for
> the sake of speed.
> 
> So, no, it is not a serious design error to allocate more space for a
> dynamic array than is absolutely necessary.  In fact, it's a serious
> design asset :)

My point, which I believe should be clear to anyone following this
subthread, is that it would be a serious design error to allocate more
space than is absolutely necessary, when the space needed is ZERO.

Please explain how it would be advantageous for the following code to
allocate 1,000,000+ array elements:

my @array;
if ($array[1_000_000]) {
  print "Whoa!\n"
}


Ronald

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe