Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Evolution is a million line computer program falling into place by accident.


devel / comp.lang.tcl / Understanding Tcl memory management of list created in C

SubjectAuthor
o Understanding Tcl memory management of list created in Cclt.to.davebr

1
Understanding Tcl memory management of list created in C

<0681666717120@dlp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=9898&group=comp.lang.tcl#9898

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: clt.to.d...@dfgh.net
Newsgroups: comp.lang.tcl
Subject: Understanding Tcl memory management of list created in C
Date: Tue, 25 Oct 22 16:58:40 GMT
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <0681666717120@dlp>
Injection-Info: reader01.eternal-september.org; posting-host="11643038e3b490870bfa9bd76fa1b29b";
logging-data="2204501"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199vuaZI0Qaewj+M0XUL0hj"
Cancel-Lock: sha1:j3oxtVDXSvgUdHg797TYglEhl5A=
 by: clt.to.d...@dfgh.net - Tue, 25 Oct 2022 16:58 UTC

>From: Harald Oehlmann <wortkarg3@yahoo.com>
>Date: Tue Oct 25 10:07:16 GMT 2022
>Subject: Understanding Tcl memory management of list created in C

Another interesting nitpick

set B [list {*}$lA]

is about twice as fast as:

lappend B {*}$A

for long lists on my machine, and does not assume B starts empty, or does not yet exist.

In any case I can think of, a fast and safe way to copy a long list (saved in A), then append "zzz" to the copy (while saving the original list in A) would be:

set B $A
lappend B zzz

In this case the first step is very fast (copying a pointer to the original list), and the second is slow (because the original list is duplicated by Tcl's internal copy on write logic before it is modified). Which is very close to Gertjan's thoughts on relative timings.

Dave B

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor