Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

186,000 Miles per Second. It's not just a good idea. IT'S THE LAW.


devel / comp.lang.tcl / Re: Accessing Tcl dict from C API

SubjectAuthor
* Accessing Tcl dict from C APIAlexandru
`* Re: Accessing Tcl dict from C APIRalf Fassel
 `* Re: Accessing Tcl dict from C APIHarald Oehlmann
  +- Re: Accessing Tcl dict from C APIAlexandru
  `- Re: Accessing Tcl dict from C APIRalf Fassel

1
Accessing Tcl dict from C API

<a60ce117-dc21-48e2-befd-e842a8074036n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a05:6214:c6e:b0:681:5e16:3cde with SMTP id t14-20020a0562140c6e00b006815e163cdemr344613qvj.11.1705353958309;
Mon, 15 Jan 2024 13:25:58 -0800 (PST)
X-Received: by 2002:a05:6214:2582:b0:681:59de:68ca with SMTP id
fq2-20020a056214258200b0068159de68camr335239qvb.12.1705353958147; Mon, 15 Jan
2024 13:25:58 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Mon, 15 Jan 2024 13:25:57 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=2001:9e8:8922:4a00:9418:91ea:77f3:7b28;
posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 2001:9e8:8922:4a00:9418:91ea:77f3:7b28
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a60ce117-dc21-48e2-befd-e842a8074036n@googlegroups.com>
Subject: Accessing Tcl dict from C API
From: alexandr...@meshparts.de (Alexandru)
Injection-Date: Mon, 15 Jan 2024 21:25:58 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2619
 by: Alexandru - Mon, 15 Jan 2024 21:25 UTC

I have some C functions that perform fast operations on lists of numbers.
Until now, I transfer Tcl data in the shape of lists to those C functions.
In some cases the Tcl data is stored in dictionaries so I run some Tcl loops over the Tcl dict, put the needed data into lists and finally pass the lists to the C function.
Since performance is paramount, I'm thinking that the above method might not be the fastest.
If I would directly pass the Tcl dict to the C function, would that be faster?
What if the Tcl dict is "nested" so there are multiple keys that lead to a value?
Can I (efficiently) access nested dicts with the C API?
The examples found on the Wiki and Help are always about simple (array like) dicts (not nested). I have a hunch, that nested dicts might get things much more complicated and/or inefficient.

Another idea that I'm having is writing some C functions that help me to store the dict data directly in C instead of storing it first in Tcl, then transfer to C. For example, I would need a Tcl/C function that does the equivalent to "dict set", let's say "c2tcl::dict_set". Then I could access the value with "c2tcl::dict_get". When I need to perform large operations on the whole dict, then I don't need to transfer it from Tcl to C first, because it's already in C. Not sure though how this copes with Tcl treads.

I hope you can give me some advice to any of the two methos, before I start putting the effort in programing.

Many thanks
Alexandru

Re: Accessing Tcl dict from C API

<ygasf2xnw8h.fsf@panther.akutech-local.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Accessing Tcl dict from C API
Date: Tue, 16 Jan 2024 16:17:34 +0100
Lines: 31
Message-ID: <ygasf2xnw8h.fsf@panther.akutech-local.de>
References: <a60ce117-dc21-48e2-befd-e842a8074036n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net mCD7j0DqBSAnyRSlm+AQcwBV0hmM3Vrsx42nxCLUQxXlrIMXI=
Cancel-Lock: sha1:SkMChE/+VATi4nZOo0WvlGl+Qlo= sha1:dIZo7IPX+3GQM1zJijnSvFF9m48= sha256:sdFVB/3H+tGi3divwuEC1Q4cDbYUIe81HX5Ajs07NLs=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Tue, 16 Jan 2024 15:17 UTC

* Alexandru <alexandru.dadalau@meshparts.de>
| I have some C functions that perform fast operations on lists of numbers.
| Until now, I transfer Tcl data in the shape of lists to those C functions.
| In some cases the Tcl data is stored in dictionaries so I run some Tcl
| loops over the Tcl dict, put the needed data into lists and finally
| pass the lists to the C function.
| Since performance is paramount, I'm thinking that the above method might not be the fastest.
| If I would directly pass the Tcl dict to the C function, would that be faster?

Not copying data sounds always faster to me...

https://www.tcl.tk/man/tcl8.6/TclLib/DictObj.html

lists the C interface to dicts. Basically you get the TclObjs for the
keys and/or values in the dict. You would then call Tcl_GetIntFromObj()
on the value ptr.

| What if the Tcl dict is "nested" so there are multiple keys that lead to a value?

You would need some information on the nesting depth, since the value
has no "I'm a dict" label attached. You could check whether
Tcl_GetIntFromObj(valueptr) is successful and if not, try to use it as
multiple-level dict.

| Can I (efficiently) access nested dicts with the C API?

I would say 'yes', since in nested dicts the values are themselves just
dicts instead of plain... well... 'values'. Haven't tried that myself, though.

HTH
R'

Re: Accessing Tcl dict from C API

<uo687m$1gfb8$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.furie.org.uk!nntp.terraraq.uk!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: Accessing Tcl dict from C API
Date: Tue, 16 Jan 2024 16:43:51 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uo687m$1gfb8$1@dont-email.me>
References: <a60ce117-dc21-48e2-befd-e842a8074036n@googlegroups.com>
<ygasf2xnw8h.fsf@panther.akutech-local.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 16 Jan 2024 15:43:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0a26ed7744814b88569eb9ef62eb6de9";
logging-data="1588584"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XuYOYK3oym+1WQL7teJtZ"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:UgGmt/4ssSRmTeWSf38NJk+e8cc=
In-Reply-To: <ygasf2xnw8h.fsf@panther.akutech-local.de>
Content-Language: en-GB
 by: Harald Oehlmann - Tue, 16 Jan 2024 15:43 UTC

Am 16.01.2024 um 16:17 schrieb Ralf Fassel:
> | Can I (efficiently) access nested dicts with the C API?
>
> I would say 'yes', since in nested dicts the values are themselves just
> dicts instead of plain... well... 'values'. Haven't tried that myself, though.

I confirm that this works: nested dicts from C.
There is no buildin for it, so it should be programmed manually:

TCL_OBJ * subdict;

if (TCL_OK == Tcl_DictObjGet(interp, dictPtr, keyPtr, subdict)
&& TCL_OK == Tcl_DictObjGet(interp, subdict, keyPtr, valuePtrPtr) )

Re: Accessing Tcl dict from C API

<7adad762-bb95-4838-a1d6-f9222edaac05n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a0c:ee47:0:b0:681:5540:c31a with SMTP id m7-20020a0cee47000000b006815540c31amr473296qvs.12.1705423052260;
Tue, 16 Jan 2024 08:37:32 -0800 (PST)
X-Received: by 2002:a05:6214:627:b0:680:d38e:d041 with SMTP id
a7-20020a056214062700b00680d38ed041mr892543qvx.10.1705423052065; Tue, 16 Jan
2024 08:37:32 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Tue, 16 Jan 2024 08:37:31 -0800 (PST)
In-Reply-To: <uo687m$1gfb8$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=176.3.195.205; posting-account=glPZ8goAAADztwA3kVEZPMKXCGydx5DU
NNTP-Posting-Host: 176.3.195.205
References: <a60ce117-dc21-48e2-befd-e842a8074036n@googlegroups.com>
<ygasf2xnw8h.fsf@panther.akutech-local.de> <uo687m$1gfb8$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7adad762-bb95-4838-a1d6-f9222edaac05n@googlegroups.com>
Subject: Re: Accessing Tcl dict from C API
From: alexandr...@meshparts.de (Alexandru)
Injection-Date: Tue, 16 Jan 2024 16:37:32 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Alexandru - Tue, 16 Jan 2024 16:37 UTC

Harald Oehlmann schrieb am Dienstag, 16. Januar 2024 um 16:43:55 UTC+1:
> Am 16.01.2024 um 16:17 schrieb Ralf Fassel:
> > | Can I (efficiently) access nested dicts with the C API?
> >
> > I would say 'yes', since in nested dicts the values are themselves just
> > dicts instead of plain... well... 'values'. Haven't tried that myself, though.
> I confirm that this works: nested dicts from C.
> There is no buildin for it, so it should be programmed manually:
>
> TCL_OBJ * subdict;
>
> if (TCL_OK == Tcl_DictObjGet(interp, dictPtr, keyPtr, subdict)
> && TCL_OK == Tcl_DictObjGet(interp, subdict, keyPtr, valuePtrPtr) )

Thanks Harald and Ralf for the hints.
I'll try to implement it and measure the speed.

Regards
Alexandru

Re: Accessing Tcl dict from C API

<ygao7dlnqu2.fsf@panther.akutech-local.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Accessing Tcl dict from C API
Date: Tue, 16 Jan 2024 18:14:13 +0100
Lines: 21
Message-ID: <ygao7dlnqu2.fsf@panther.akutech-local.de>
References: <a60ce117-dc21-48e2-befd-e842a8074036n@googlegroups.com>
<ygasf2xnw8h.fsf@panther.akutech-local.de>
<uo687m$1gfb8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net iXW9txQov3MnLBFHO30bsAjFe2nbuTbbNXF8196w+TEfy6Rwo=
Cancel-Lock: sha1:6OYs2T761FY7ipbIjI4sZPt6HMw= sha1:f6eSMYnuYvz9nElclO++BGV74HQ= sha256:cN9G2lSV0wSEXdgysbxAEgpkFirAO4KdbrtNW/vKKFs=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Tue, 16 Jan 2024 17:14 UTC

* Harald Oehlmann <wortkarg3@yahoo.com>
| Am 16.01.2024 um 16:17 schrieb Ralf Fassel:
| > | Can I (efficiently) access nested dicts with the C API?
| > I would say 'yes', since in nested dicts the values are themselves
| > just
| > dicts instead of plain... well... 'values'. Haven't tried that myself, though.
>
| I confirm that this works: nested dicts from C.
| There is no buildin for it, so it should be programmed manually:
>
| TCL_OBJ * subdict;
>
| if (TCL_OK == Tcl_DictObjGet(interp, dictPtr, keyPtr, subdict)

I *think* that needs to be

Tcl_DictObjGet(interp, dictPtr, keyPtr, &subdict)

since Tcl_DictObjGet() takes a TclObj** as last parameter.

R'

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor