home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5578 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  2.6 KB

  1. Path: sparky!uunet!mcsun!sun4nl!ltb!wierda
  2. From: wierda@ltb.ltb.bso.nl (Gerben Wierda)
  3. Newsgroups: comp.lang.perl
  4. Subject: memory problem with test program
  5. Message-ID: <2038@ltb.ltb.bso.nl>
  6. Date: 28 Aug 92 13:05:41 GMT
  7. Organization: BSO/LT, Baarn, The Netherlands
  8. Lines: 101
  9.  
  10. We have several perl programs that use a reasonable lot of data in (assoc)
  11. arrays. However, freeing those arrays does not make the memory use smaller. Is
  12. this perl? BSD?
  13.  
  14. Here is the program and the typical output. The input file has 10000 lines
  15. with info:
  16.  
  17. =======================snip snip===============================
  18. #! /usr/local/bin/perl
  19.  
  20. &memory;
  21.  
  22. open(LIST,"companylist");
  23. @normal = (<LIST>);
  24. close(LIST);
  25. print "Normal array created with ", $#normal+1, " elements\n";
  26. &memory;
  27.  
  28. open(LIST,"companylist");
  29. while (<LIST>) {
  30.   $assoc{$_} = 1;
  31. }
  32. close(LIST);
  33. print "Associative array created with ", $#normal+1, " elements\n";
  34. &memory;
  35.  
  36. undef @normal;
  37. print "Normal array undefined\n";
  38. &memory;
  39.  
  40. undef %assoc;
  41. print "Associative array undefined\n";
  42. &memory;
  43.  
  44. reset 'a', 'n';
  45. print "Arrays 'a' and 'n' reset\n";
  46. &memory;
  47.  
  48. open(LIST,"companylist");
  49. @bormal = (<LIST>);
  50. close(LIST);
  51. print "Normal array created with ", $#bormal+1, " elements\n";
  52. &memory;
  53.  
  54. open(LIST,"companylist");
  55. while (<LIST>) {
  56.   $bssoc{$_} = 1;
  57. }
  58. close(LIST);
  59. print "Associative array created with ", $#bormal+1, " elements\n";
  60. &memory;
  61.  
  62. undef @bormal;
  63. print "Normal array undefined\n";
  64. &memory;
  65.  
  66. undef %bssoc;
  67. print "Associative array undefined\n";
  68. &memory;
  69.  
  70. reset 'b';
  71. print "Arrays 'b' reset\n";
  72. &memory;
  73.  
  74. sub memory {
  75.   open(PS,"ps -u$$ |") || die "Can't run ps, $!\n";
  76.   while (<PS>) {
  77.     ($user,$pid,$cpu,$mem) = split;
  78.   }
  79.   close(PS);
  80.   print "\tMemory use is $mem%.\n";
  81. }
  82. =======================snip snip===============================
  83.     Memory use is 1.6%.
  84. Normal array created with 10141 elements
  85.     Memory use is 11.5%.
  86. Associative array created with 10141 elements
  87.     Memory use is 15.2%.
  88. Normal array undefined
  89.     Memory use is 15.2%.
  90. Associative array undefined
  91.     Memory use is 15.2%.
  92. Arrays 'a' and 'n' reset
  93.     Memory use is 15.2%.
  94. Normal array created with 10141 elements
  95.     Memory use is 15.3%.
  96. Associative array created with 10141 elements
  97.     Memory use is 15.3%.
  98. Normal array undefined
  99.     Memory use is 15.3%.
  100. Associative array undefined
  101.     Memory use is 15.3%.
  102. Arrays 'b' reset
  103.     Memory use is 15.3%.
  104.  
  105. =======================snip snip===============================
  106. -- 
  107. wierda@ltb.bso.nl (Gerben Wierda) || I speak for myself and not for my employer.
  108. (+31) 2154 84415/(+31) 35 833539  || Support the League for Programming Freedom!
  109.     "If you don't know where you are going, any road will take you there."
  110.     (Almost from) Lewis Carroll, "Alice in Wonderland".
  111.