Does using undef as hash values save any memory in Perl? -


a Perl idiom to remove duplicate values ​​from an array:

  @uniq = Keys% {{Map {$ _ = & gt; 1} @list}}  

Using this version is cheaper:

  @uniq = keys% {{Map {$ _ = & gt; ; Undef} @list}} I have tested with these one-liners, and it seems that this is true on some versions of Perl:  
  Perl -e 'my% x; $ X {$ _} = 1 for 0.000000; System "ps -ovsz $$" 'perl -e' my% x; Unfifferent for $ X {$ _} = 0..1000_000; System "ps -ovsz $$" ' 

OK, undef < / Code> is considered a flyweight value, which means that all its references indicate the same figure. You do not do this for other verbal people, you still need the upper part of the slot, though it is mentioned though. However, I do not see any memory for me on Perl 5.10 or 5.11 on Mac OS X. While the perl in is undef can not use more memory in the case, expected me to make sure it uses more memory, so it takes hold anyway . However, I am not eager to investigate memory usage in internals.

It is very useful to show these types of things

  Use # Pearl Devel !:: Peak; My $ a = lower; My $ b = uncle; Dump ($ A); Dump ($ B); My% hash = map {$ _, anonymous} 1 .. 3; $ Hash {4} = 'hello'; Dump (\% hash);  

The output looks a bit scary at first, but let's see that the undef values ​​are zero (0x0) instead of individual strings 0x100208708 REFCNT = 1 FLAGS = (PADMY) SV = nULL (0x0) REFCNT = 1 price Flags on 0x100208738 ( PV ):

  SV = nULL (0x0) 0x100805008 Arfsiatti = 1 flags = (TAMP, Aroke) RV = 0xl00208780 SV = Piviacvi (0x10080 9 8 8) REFCNT = 2 flags = on 0xl00208780 (Padmi, Seyrijh) RRE = 0x100202200 (0: 5) = 0 (0: 00805018 ) 0x100805008 = = (PADMY) SV = RV (0x100805018), 1: 2, 2: 1) hash quality = 91.7% KEYS = 4 filling = 3 Max = 7 Riter = -l Eiter = 0x0 ELT "4" HASH = 0xb803eff9 SV = PV (0x100801c78) 0x100804ed0 REFCNT = 1 the FLAGS = (PoK, pPOK) PV = 0x100202a30 "Hello" \ 0 CUR = 5 LEN = 8 ELT "1" HASH = 0x806b80c9 SV = zero (0x0) = 1 FLAGS = (on 0x100820db0 REFCNT) "3" HASH = 0xa400c7f3 REFCNT = 1 Flags = ()  
on SV = ELT Zero (0x0) 0x100820df8

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -