Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: What do agnostic, insomniac dyslexics do at night? A: Stay awake and wonder if there's a dog.


comp / comp.lang.tcl / Re: memory usage

SubjectAuthor
* memory usagesaito
`* Re: memory usageRich
 `* Re: memory usagesaito
  `* Re: memory usageHarald Oehlmann
   `- Re: memory usagesaito

1
Subject: memory usage
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 8 Aug 2024 20:21 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: memory usage
Date: Thu, 8 Aug 2024 16:21:21 -0400
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <v939c2$7nob$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 08 Aug 2024 22:21:22 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="41514af555d57b22159f4f65578b4eb5";
logging-data="253707"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19AZX2qGyQyDk5Plgu9D46D"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:/YKTcGJ4aYr5zd9EOimyPDaMDjM=
Content-Language: en-US
View all headers

Sorry this may be quite basic but just wanted to confirm it:

Let's say that I have a proc which generates a large dict and returns
it. Then when used, the caller assigns it to a variable.

How much memory is used, 10mb or 20mb? (let's ignore any extra memory
needed to manage the dict structure and the proc calls).

proc generate_10mb_dict {a b c} {
# generate a large dict, in d

return $d
}

set my_data [generate_10mb_dict $a $b $c]

what is the ram use at this point?

Subject: Re: memory usage
From: Rich
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 8 Aug 2024 20:27 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: memory usage
Date: Thu, 8 Aug 2024 20:27:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <v939oe$7pr3$1@dont-email.me>
References: <v939c2$7nob$1@dont-email.me>
Injection-Date: Thu, 08 Aug 2024 22:27:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ed48b3c552ea0813e1e524b6eaf39a8c";
logging-data="255843"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188l0SAve6d8fgeYej9Z0UG"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:pM2NWr5KnHxTF4Y7jwC3pufh5Rw=
View all headers

saito <saitology9@gmail.com> wrote:
> Sorry this may be quite basic but just wanted to confirm it:
>
> Let's say that I have a proc which generates a large dict and returns
> it. Then when used, the caller assigns it to a variable.
>
> How much memory is used, 10mb or 20mb? (let's ignore any extra memory
> needed to manage the dict structure and the proc calls).
>
>
> proc generate_10mb_dict {a b c} {
> # generate a large dict, in d
>
> return $d
> }
>
> set my_data [generate_10mb_dict $a $b $c]
>
>
> what is the ram use at this point?

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.

Subject: Re: memory usage
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Thu, 8 Aug 2024 23:39 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: memory usage
Date: Thu, 8 Aug 2024 19:39:27 -0400
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <v93kvh$b1js$1@dont-email.me>
References: <v939c2$7nob$1@dont-email.me> <v939oe$7pr3$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 01:39:30 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d38041fef7556fc50fa4e7a83475fcc7";
logging-data="362108"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lpxmMxg3MVNU6MMe5Yd3w"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:v+wCI4u8ueKvyU+STagYFzOQ5ms=
Content-Language: en-US
In-Reply-To: <v939oe$7pr3$1@dont-email.me>
View all headers

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!

Subject: Re: memory usage
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 9 Aug 2024 06:22 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortkarg3@yahoo.com (Harald Oehlmann)
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>
View all headers

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

Subject: Re: memory usage
From: saito
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 9 Aug 2024 16:07 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: saitology9@gmail.com (saito)
Newsgroups: comp.lang.tcl
Subject: Re: memory usage
Date: Fri, 9 Aug 2024 12:07:01 -0400
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <v95er6$pu5p$1@dont-email.me>
References: <v939c2$7nob$1@dont-email.me> <v939oe$7pr3$1@dont-email.me>
<v93kvh$b1js$1@dont-email.me> <v94cjj$jp7f$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 18:07:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="9adabf7bb8964dc0ee570b587cebc8cf";
logging-data="850105"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lZeXPKxuuDZFTBQYZjAxo"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ThFO3/dYNRmXYmLlwyhL0seumZ0=
Content-Language: en-US
In-Reply-To: <v94cjj$jp7f$1@dont-email.me>
View all headers

On 8/9/2024 2:22 AM, Harald Oehlmann wrote:
>
> Now, dict item a and b are differently and thus b is copied.
>
> Anyway, it is endlessly complicated...
>

:-)

Thanks for the details. That makes sense.

1

rocksolid light 0.9.8
clearnet tor