This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

ByteCount

ByteCount[expr]
gives the number of bytes used internally by Mathematica to store expr.
  • ByteCount does not take account of any sharing of subexpressions. The results it gives assume that every part of the expression is stored separately. ByteCount will therefore often give an overestimate of the amount of memory currently needed to store a particular expression. When you manipulate the expression, however, subexpressions will often stop being shared, and the amount of memory needed will be close to the value returned by ByteCount. »
  • Results from ByteCount may be different on different computer systems.
Find the number of bytes used to store an expression:
Plot the ByteCount for different types of expressions:
Find the number of bytes used to store an expression:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
 
Plot the ByteCount for different types of expressions:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
Growth of storage sizes for a sequence of integrals:
Make Simplify pick expressions with minimum ByteCount:
LeafCount does not account for sizes of numbers:
Show that lists with symbolic elements require more storage than lists of numbers:
On the computer system used for this example, each ordinary integer takes 4 bytes to store:
Approximate numbers take double:
ByteCount does not account for sharing in the actual storage of expressions:
Symbols are effectively always shared, so they give 0 byte count:
For ASCII strings, ByteCount on average increases by 1 for each character:
Unicode characters on average add 2 bytes each:
For integers, there is a jump in going beyond machine numbers:
The average rate of increase is about 0.4 bytes per decimal digit:
Each element of a list effectively adds an internal pointer:
MemoryConstrained aborts the generation of expressions that exceed a specified ByteCount:
Small changes can have large effects on memory usage:
The presence of the exact prevents the data from being packed:
ByteCount only gives the size of handles to external objects:
New in 1