Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What value should be given to a Tcl dict for minimum memory?

I need a dictionary, "just for the keys", that is, the values are of lesser importance. Which value will consume the least amount of memory? "0" "", something else? Thanks.

like image 443
user1134991 Avatar asked Mar 18 '23 01:03

user1134991


1 Answers

Tcl shares constants under the covers, so you can use pretty much anything as long as it is a literal. But the empty string is almost certainly going to be a pre-defined constant in your script anyway (even if you don't notice it) and is pretty short. Or go with a single-character alphanumeric string, which will generate a shorter string form of dictionary (and have practically no difference otherwise). A 0 is a single-character alphanumeric string, of course.

In my own code, I would mostly use something like "dummy value" for the value. The cost is only a few bytes total more most of the time, and yet it's much clearer to me that it doesn't mean anything, so if I come back to the code later I don't try to figure out what I was doing with the value…

like image 166
Donal Fellows Avatar answered Apr 28 '23 08:04

Donal Fellows