2 sizeof - number of bytes required for value
13 This is analogous to the C operator sizeof for the value only.
14 It attempts to assess the number of bytes in memory used to store
15 a value and all of its components. Unlike memsize(x), this
16 builtin does not include the size of the overhead.
18 Unlike size(x), this builtin incldues the trailing \0 byte on the
21 For numeric values, sizeof(x) ignores the demoninator if 'x' is
22 an integer. For complex values, sizeof(x) ignores the imaginary
23 part if 'x' is real. Because the 0, 1 and -1 numeric values are
24 shared static values, sizeof(x) reports such values as having
27 The number returned by sizeof(x) may be less than the actual number
28 used because, for example, more memory may have been allocated for
29 a string than is used: only the characters up to and including the
30 first '\0' are counted in calculating the contribution of the
33 The number returned by sizeof(x) may be greater (and indeed
34 substantially greater) than the number of bytes actually used.
40 the numerical information for a, A[0], A[1], A[2] are stored in the
41 same memory, so the memory used for A is the same as if
42 its 3 elements were null values. The value returned by
43 sizeof(A) is calculated as A were defined by:
45 mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}.
47 Similar sharing of memory occurs with literal strings.
49 For associative arrays, only the value part of the name/value pair
52 The minimum value for sizeof(x) occurs for the null and error values.
55 The results for examples like these will depend to some extent on
56 the system being used. The following were for an SGI R4k machine
59 ; print sizeof(null()), sizeof(0), sizeof(3), sizeof(2^32 - 1), sizeof(2^32)
62 ; x = sqrt(2, 1e-100); print sizeof(x), sizeof(num(x)), sizeof(den(x))
65 ; print sizeof(list()), sizeof(list(1)), sizeof(list(1,2))
68 ; print sizeof(list()),sizeof(list(1)),sizeof(list(1,2)),sizeof(list(1,2,3))
71 ; mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100];
72 ; print sizeof(A), sizeof(B), sizeof(C), sizeof(D)
76 ; obj point P = {1,2,3}; print sizeof(P)
80 It is assumed sizeof(x) will fit into a system long integer.
86 size, fsize, strlen, digits
88 ## Copyright (C) 1999 Landon Curt Noll
90 ## Calc is open software; you can redistribute it and/or modify it under
91 ## the terms of the version 2.1 of the GNU Lesser General Public License
92 ## as published by the Free Software Foundation.
94 ## Calc is distributed in the hope that it will be useful, but WITHOUT
95 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
96 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
97 ## Public License for more details.
99 ## A copy of version 2.1 of the GNU Lesser General Public License is
100 ## distributed with calc under the filename COPYING-LGPL. You should have
101 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
102 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
104 ## @(#) $Revision: 30.1 $
105 ## @(#) $Id: sizeof,v 30.1 2007/03/16 11:10:42 chongo Exp $
106 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/sizeof,v $
108 ## Under source code control: 1996/05/24 02:04:04
109 ## File existed as early as: 1996
111 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
112 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/