in reply to Re: Array or Hash
in thread Array or Hash
Are you sure about that? Unlike C, perl can do sparse arrays without using lots of memory for the empty slots, so you can write:
my @test = (); $test[ 0 ] = 'first'; $test[ 10_000_000 ] = 'last';
If the array index was used to directly calculate the RAM location of the data, then perl would have to allocate lots of it for the table. The fact that the code above works suggests that perl keeps a lookup table somewhere of valid values. That lookup table will be similar to the one needed for a hash, and potentially no faster.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Array or Hash
by BrowserUk (Patriarch) on Jan 21, 2011 at 09:47 UTC | |
by chrestomanci (Priest) on Jan 21, 2011 at 16:14 UTC | |
by BrowserUk (Patriarch) on Jan 21, 2011 at 16:54 UTC | |
by ahmad (Hermit) on Jan 21, 2011 at 15:41 UTC | |
by BrowserUk (Patriarch) on Jan 21, 2011 at 15:43 UTC | |
|
Re^3: Array or Hash
by ikegami (Patriarch) on Jan 21, 2011 at 09:46 UTC |