in reply to Re: Re: Re: Weighting rand()
in thread Weighting rand()

The size of a scalar has a minimum overhead. Anything below about 20 characters (guess) in length requires the same amount of memory
Er, no. A scalar that is only ever used as a number will use less memory than a scalar used as a string (even one of zero length).
$ perl -e 'push @a, 1 for 1..100000; system"ps -flp $$"' .... SZ .... 608 $ perl -e 'push @a, "" for 1..100000; system"ps -flp $$"' .... SZ .... 905

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Weighting rand()
by BrowserUk (Patriarch) on May 25, 2004 at 11:30 UTC

    Even so, there is still an overhead of 24 bytes per element of the array before you put anything in it. If you have to create a second array (list) to hold the indexes, the weightings have to be pretty large for the savings in replicating the indexes rather than the strings, to balance out the cost of creating that second list.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail