home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnusmalltalk / examples / mem-usage.st < prev    next >
Text File  |  1992-02-15  |  2KB  |  56 lines

  1. "Compute the amount of memory and the number of instances for each
  2.  Class in the GNU Smalltalk system."
  3.  
  4.  
  5. "======================================================================
  6. |
  7. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  8. | Written by Steve Byrne.
  9. |
  10. | This file is part of GNU Smalltalk.
  11. |
  12. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  13. | under the terms of the GNU General Public License as published by the Free
  14. | Software Foundation; either version 1, or (at your option) any later version.
  15. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  16. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  18. | details.
  19. | You should have received a copy of the GNU General Public License along with
  20. | GNU Smalltalk; see the file LICENSE.  If not, write to the Free Software
  21. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  22. |
  23.  ======================================================================"
  24.  
  25.  
  26.  
  27. !Object methodsFor: 'demo'!
  28.  
  29. showMemUsage
  30.     | t numObjs classObjs totalInstanceSize instVarSize |
  31.     numObjs _ t _ 0.
  32.     Object withAllSubclasses do: 
  33.     [ :class | class printNl.
  34.            totalInstanceSize _ classObjs _ 0.
  35.            instVarSize _ class instSize.
  36.                    (class == MethodContext or: [ class == BlockContext ])
  37.                ifFalse: [ class allInstancesDo:
  38.                       [ :inst | totalInstanceSize _ totalInstanceSize +
  39.                             ((WordMemory at: (Memory addressOf: inst)) * 4).
  40.                         classObjs _ classObjs + 1 ] 
  41.                       ].
  42.                             
  43.            stdout nextPutAll: '  Instances: '. classObjs printNl.
  44.            stdout nextPutAll: '  Size: '. totalInstanceSize printNl.
  45.            stdout nl.
  46.            t _ t + totalInstanceSize.
  47.            numObjs _ numObjs + classObjs ].
  48.  
  49.     numObjs printNl.
  50.     t printNl
  51. !!
  52.  
  53. Object showMemUsage!
  54.