more useful options | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I don't remember where I read it (probably in the Panther book) but Perl arrays are designed to easily compete with linked lists, while keeping the benefits of indexed access.
That is to allow dynamic growth on both ends in a very dynamic way. An array has an internal index for the first and last element and allocates twice as much space as reserve for push or unshift. Basically only the range between the first and last existing element need to be stored, plus mentioned reserve. The existing elements are kind of pointers to scalars which are allocated separately. Allocation of new space is only needed if the reserve elements are filled, since this happens in exponential steps of doubling* it's statistically very efficient. Shrinking the array happens just by adjusting the indices for the first and last element. HTH
Cheers Rolf
updatesee here Shift, Pop, Unshift and Push with Impunity! *) not sure anymore about the doubling, maybe confusing that part with hashes. In reply to Re^3: Difference between exists and defined
by LanX
|
|