So... how do you measure memory usage in Python? Every programming
language I've used before (not a huge range, I'll admit) had *some* sort
of facility to measure memory usage, typically things like:
* how much memory is free in the stack?
* how much memory is free in the heap?
* how big a block does this pointer point to?
* how much memory does this record/struct/object/string use?
Well, in my 30 years with various languages -- FORTRAN (IV under
CP/V, 77 & 90 under VMS), COBOL, a smidgen of APL, a pinch of LISP
(TRS-80!), Pascal (UCSD, Alcor, DEC), Ada, C/C++ (TRSDOS, Amiga, DEC,
Windows), Python, VB6, (A)Rexx -- I've never encountered such items
supported by the language.
OS specific extensions MIGHT supply it... For example, if one can
obtain the size of the stack allocated to the process, and then the
address of the current top-of-stack, computing the free stack space is a
simple operation.
Determining free heap space is not as easy, unless it either does
free-space compression (the old Macintosh double pointer handle scheme,
where it could move the end-object to compress heap, by only updating
the pointer in the handle structure which doesn't get moved).
"how big a block"... On the Amiga, I believe that was available by
playing games -- negative indexing from the start of the malloc'd memory
would get one into a "block header" that defined the length of the
block; used when chaining the linked list of heap space upon free (if
block A ends where block B began, and both are free, combine into a
single block AB)
As for generic object size... Typically by reading the detailed
language manual, and then hand calculations.
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/