Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: mem usage

by halfcountplus (Hermit)
on May 26, 2010 at 18:40 UTC ( #841784=note: print w/replies, xml ) Need Help??


in reply to Re^3: mem usage
in thread mem usage

Hmmm, yeah that's much better. What's the significance of this:
@a=();
After presizing -- I would have thought that would just clear the array?

Replies are listed 'Best First'.
Re^5: mem usage
by ikegami (Pope) on May 26, 2010 at 19:00 UTC

    It does indeed clear the array, but it does not free it the underlying buffer.

    Setting $#a extends the visible size of the array, not just the internal one. The elements I proceeded to push onto the array were getting added after the 12 mil empty ones.

    @a=(); empties the visible array, but doesn't deallocate the internal buffer like undef @a; does.

    $ perl -MDevel::Peek -e' my @a = qw( a b c ); Dump(\@a,1); @a=(); Dump(\@a,1); undef(@a); Dump(\@a,1); ' SV = IV(0x816ce54) at 0x816ce58 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x817bc50 SV = PVAV(0x816d038) at 0x817bc50 REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x817b500 FILL = 2 <---- 3 elements MAX = 3 <---- 4 slots ARYLEN = 0x0 FLAGS = (REAL) SV = IV(0x816c154) at 0x816c158 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x817bc50 SV = PVAV(0x816d038) at 0x817bc50 REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x817b500 FILL = -1 <---- 0 elements MAX = 3 <---- 4 slots ARYLEN = 0x0 FLAGS = (REAL) SV = IV(0x816c154) at 0x816c158 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x817bc50 SV = PVAV(0x816d038) at 0x817bc50 REFCNT = 2 FLAGS = (PADMY) ARRAY = 0x0 <---- No array allocated FILL = -1 <---- 0 elements MAX = -1 <---- 0 slots ARYLEN = 0x0 FLAGS = (REAL)

    If you don't want to rely on that, you could do

    my @lines; $#lines = 12_000_000; $lines[$.-1] = $_ while <>; $#lines = $.-1;
      Devel::Peek looks interesting. Thanks again.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://841784]
help
Chatterbox?
[holli]: but then you DO give a fuck
[1nickt]: I don;t think beliefs should be down-voted, just behaviours.
[james28909]: im not quite how to explain it any better nick. you evolved from ignorance to intelligence. not the other way. the universe evolves from gas coulds and debris into planets stars and galaxies ect. it doesnt happen any other way. hence it has ....
[james28909]: some kind of logic behind it
[james28909]: and that is also anothe rpoint i made, i think it has to do with perception of the world around you. most people think of evolution on a human scale. why could life evolve on this planet? because this planet evolved in this solar system. and so on.
[holli]: here's something for you to watch, James. I think you will like it
[erix]: for the record: I have not downvoted anyone on that subthread that was my fault
[james28909]: there are all kinds of things that had to happen to let life come to be. but at the same time, life may not be the end goal IF there is any kind of end goal lol
[james28909]: well who is the person who gets to decide which behaviour is worthy of a downvote? a person with their own beliefs? xD
[erix]: teleology -- I've never understood why that was thunk up

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (18)
As of 2017-12-15 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (433 votes). Check out past polls.

    Notices?