NAME
    memsize - number of bytes required for value including overhead

SYNOPSIS
    memsize(x)

TYPES
    x		any

    return	integer

DESCRIPTION
    This is analogous to the C operator sizeof.	 It attempts to assess
    the number of bytes in memory used to store a value and all its
    components plus all of the related structue overhead.  Unlike
    sizeof(x), this builtin includes overhead.

    Unlike size(x), this builtin incldues the trailing \0 byte on the
    end of strings.

    Unlike sizeof(x), this builtin includes the size demonitor for integers
    and the imaginary part for complex values.	Storage for holding
    0, 1 and -1 values are also included.

    The number returned by memsize(x) may be less than the actual number
    used because, for example, more memory may have been allocated for
    a string than is used: only the characters up to and including the
    first '\0' are counted in calculating the contribution of the
    string to memsize(x).

    The number returned by memsize(x) may be greater (and indeed
    substantially greater) than the number of bytes actually used.
    For example, after:

		a = sqrt(2);
		mat A[3] = {a, a, a};

    the numerical information for a, A[0], A[1], A[2] are stored in the
    same memory, so the memory used for A is the same as if
    its 3 elements were null values.  The value returned by
    memsize(A) is calculated as A were defined by:

		mat A[3] = {sqrt(2), sqrt(2), sqrt(2)}.

    Similar sharing of memory occurs with literal strings.

    For associative arrays, both the name part and the value part of
    the name/value pair are counted.

    The minimum value for memsize(x) occurs for the null and error values.

EXAMPLES

    The results for examples like these will depend to some extent on
    the system being used.  The following were for an SGI R4k machine
    in 32-bit mode:

    > print memsize(null())
    8

    > print memsize(0), memsize(3), memsize(2^32 - 1), memsize(2^32)
    68 68 68 72

    > x = sqrt(2, 1e-100); print memsize(x), memsize(num(x)), memsize(den(x))
    148 108 108

    > print memsize(list()), memsize(list(1)), memsize(list(1,2))
    28 104 180

    > print memsize(list())
    28

    > print ,memsize(list(1)),memsize(list(1,2)),memsize(list(1,2,3))
    104 180 256

    > mat A[] = {1}; mat B[] = {1,2}; mat C[] = {1,2,3}; mat D[100,100];
    > print memsize(A), memsize(B), memsize(C), memsize(D)
    124 192 260 680056

    > obj point {x,y,z}
    > obj point P = {1,2,3}; print memsize(P)
    274

LIMITS
    It is assumed memsize(x) will fit into a system long integer.

LINK LIBRARY
    none

SEE ALSO
    size, sizeof, fsize, strlen, digits

## Copyright (C) 1999  Landon Curt Noll
##
## Calc is open software; you can redistribute it and/or modify it under
## the terms of the version 2.1 of the GNU Lesser General Public License
## as published by the Free Software Foundation.
##
## Calc is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
## or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU Lesser General
## Public License for more details.
##
## A copy of version 2.1 of the GNU Lesser General Public License is
## distributed with calc under the filename COPYING-LGPL.  You should have
## received a copy with calc; if not, write to Free Software Foundation, Inc.
## 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
##
## @(#) $Revision: 29.2 $
## @(#) $Id: memsize,v 29.2 2000/06/07 14:02:33 chongo Exp $
## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/memsize,v $
##
## Under source code control:	1997/03/23 20:28:02
## File existed as early as:	1997
##
## chongo <was here> /\oo/\	http://www.isthe.com/chongo/
## Share and enjoy!  :-)	http://www.isthe.com/chongo/tech/comp/calc/
