MB I sometimes want to compute the size which is required by a multi-dimensionnal array. Now the arraybytesize package does the computation for me :
http://tclrep.cvs.sourceforge.net/viewvc/tclrep/modules/arraybytesize/
The single thing to remember is the map from basic data types to the number of bytes required to store them. The following is the map used in arraybytesize :
shortinteger (8 bits) : 2 bytes
integer (32 bits) : 4 bytes
longinteger (32 bits) : 4 bytes
longlonginteger (64 bits) : 8 bytes
singlereal (32 bits) : 4 bytes
doublereal (64 bits) : 8 bytesThe following is an example of a basic use of the "bytesize" method. The memory needed to store a 3500 x 3500 integer matrix is equal to 49.0 MB (which is more human-readable than 49000000 bytes isn'it ?).
set myarray [arraybytesize create %AUTO%]
$myarray configure -rank 2
$myarray configure -verbose 1
$myarray setdimension 0 3500
$myarray setdimension 1 3500
set size [$myarray size]
set bytesize [$myarray bytesize]
set hrbytesize [$myarray bytesize 1]
$myarray destroy