2 memsize - number of bytes required for value including overhead
13 This is analogous to the C operator sizeof. It attempts to assess
14 the number of bytes in memory used to store a value and all its
15 components plus all of the related structue overhead. Unlike
16 sizeof(x), this builtin includes overhead.
18 Unlike size(x), this builtin incldues the trailing \0 byte on the
21 Unlike sizeof(x), this builtin includes the size demonitor for integers
22 and the imaginary part for complex values. Storage for holding
23 0, 1 and -1 values are also included.
25 The number returned by memsize(x) may be less than the actual number
26 used because, for example, more memory may have been allocated for
27 a string than is used: only the characters up to and including the
28 first '\0' are counted in calculating the contribution of the
31 The number returned by memsize(x) may be greater (and indeed
32 substantially greater) than the number of bytes actually used.
38 the numerical information for a, A[0], A[1], A[2] are stored in the
39 same memory, so the memory used for A is the same as if
40 its 3 elements were null values. The value returned by
41 memsize(A) is calculated as A were defined by:
43 mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}.
45 Similar sharing of memory occurs with literal strings.
47 For associative arrays, both the name part and the value part of
48 the name/value pair are counted.
50 The minimum value for memsize(x) occurs for the null and error values.
54 The results for examples like these will depend to some extent on
55 the system being used. The following were for an SGI R4k machine
58 ; print memsize(null())
61 ; print memsize(0), memsize(3), memsize(2^32 - 1), memsize(2^32)
64 ; x = sqrt(2, 1e-100); print memsize(x), memsize(num(x)), memsize(den(x))
67 ; print memsize(list()), memsize(list(1)), memsize(list(1,2))
70 ; print memsize(list())
73 ; print ,memsize(list(1)),memsize(list(1,2)),memsize(list(1,2,3))
76 ; mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100];
77 ; print memsize(A), memsize(B), memsize(C), memsize(D)
81 ; obj point P = {1,2,3}; print memsize(P)
85 It is assumed memsize(x) will fit into a system long integer.
91 size, sizeof, fsize, strlen, digits
93 ## Copyright (C) 1999 Landon Curt Noll
95 ## Calc is open software; you can redistribute it and/or modify it under
96 ## the terms of the version 2.1 of the GNU Lesser General Public License
97 ## as published by the Free Software Foundation.
99 ## Calc is distributed in the hope that it will be useful, but WITHOUT
100 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
101 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
102 ## Public License for more details.
104 ## A copy of version 2.1 of the GNU Lesser General Public License is
105 ## distributed with calc under the filename COPYING-LGPL. You should have
106 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
107 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
109 ## @(#) $Revision: 30.1 $
110 ## @(#) $Id: memsize,v 30.1 2007/03/16 11:10:42 chongo Exp $
111 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/memsize,v $
113 ## Under source code control: 1997/03/23 20:28:02
114 ## File existed as early as: 1997
116 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
117 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/