Deutsch   English   Français   Italiano  
<v94cjj$jp7f$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Harald Oehlmann <wortkarg3@yahoo.com>
Newsgroups: comp.lang.tcl
Subject: Re: memory usage
Date: Fri, 9 Aug 2024 08:22:44 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <v94cjj$jp7f$1@dont-email.me>
References: <v939c2$7nob$1@dont-email.me> <v939oe$7pr3$1@dont-email.me>
 <v93kvh$b1js$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 09 Aug 2024 08:22:43 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="433cb7267f0c4a6f0a5109670ffffb3f";
	logging-data="648431"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+/5ljWB2bcKsneSIwfekrz"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xZg+1IHZ6T2bpTPrsY5Dqi9+cRI=
Content-Language: en-GB
In-Reply-To: <v93kvh$b1js$1@dont-email.me>
Bytes: 1899

Am 09.08.2024 um 01:39 schrieb saito:
> On 8/8/2024 4:27 PM, Rich wrote:
>>
>> Given your sample code, the usage is the amount taken up by the dict.
>>
>> If the dict is 10mb (as you suggest) then after "set my_data" the ram
>> usage is 10mb.
> 
> Thank you!

Yes, TCL uses generally shared values with referent count.
And each item is reference counted. And with TCL 9, even sublists are 
reference counted, e.g. stored only once.

That means:

set d [dict create a [string repeat a 100000]]

-> d and a are reference counted.

dict set d b [dict get $d a]

does not copy the string, but reference it twice.

A copy of the data is only done, if the data gets different:

dict set d b "[dict get $d b]q"

Now, dict item a and b are differently and thus b is copied.

Anyway, it is endlessly complicated...

Harald