This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

sizeof() for tcl

Old posts that have not been replied to for several years.
Locked
Z
Zsac
Voice
Posts: 15
Joined: Sun Nov 17, 2002 10:12 pm

sizeof() for tcl

Post by Zsac »

is there an equivalent command to sizeof() for c++ in tcl? i would like to grab the size of a variable but i can't find any commands that seam to be of use.

thanks
P
Progeny

Re: sizeof() for tcl

Post by Progeny »

Hello, you can try to use:
set var [llength $string]
Z
Zsac
Voice
Posts: 15
Joined: Sun Nov 17, 2002 10:12 pm

Post by Zsac »

thats the length of the list. maybe i wasn't clear, i want the actual size as in bits, bytes etc etc.

thanks
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Tcl provides "llength" and "string length" to obtain character and list lengths.

When it comes to strings, it's simple enough to say 3 characters are 3 bytes long (as Tcl doesn't use a null terminator, though it's memory will, this is upt o you to count for if you so wish).

When it comes to numbers in C/++, things are not the same.

To place things in basics (I am no expert, and I am going from memory). With numbers, 1 byte can hold the values 0 through to 255, and 2 bytes can hold 0 through 65535.

In reality, a 1 byte number, and a 1 byte character are the same things, as the character is selected from 1 of 256 possible values/characters.

What he is asking, is if you have the two values "hello" and "255", how do you get them memory usage values from these. "hello" would produce 5 (without any null terminator, again see above) and "255" would produce 1.

Anyway, to the actual question.

Esentialy, no.

"string length" will help you for characters (depending on your needs). As for numbers, it could be possible to use some math against the values, to generate a sizeof value.

The "string is" commands could help you determine the type of variable, which would allow for a multi-purpose single command for the job.
Locked