For Programmers: Free Programming Magazines  


Home > Archive > Tcl > December 2007 > Design question, Tcl/Tk <=> C data ...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Design question, Tcl/Tk <=> C data ...
spam@controlq.com

2007-12-19, 7:16 pm


In managing database objects, I use C based list objects which are similar
to the old style (int argc, char **argv) of Tcl arg passing, and in
addition, a form of "tagged list" which corresponds pretty closely to Tcl
associative arrays, where each of the array elements are lists of the
above kind, referenced by a "string" tag rather than a numerical index.

I need to be able to pass data back and forth between the C interface to
the database manager, and Tcl/TK for CRUD operations, and while I'd like
to minimize the copying of data insofar as possible, however, portability
is an issue, and I'd prefer to use published API's rather than try to use
Tcl's internal structs to avoid this (I'd like this code not to break post
8.5.0).

A simple approach in the C -> Tcl direction would be to pass a string in
the form of an array set {} command, but shimmering might be an issue in
creating the Tcl object, and I'd still have to manually parse the array
and re-create the tagged list on the C side for the return (Tcl ->C) trip.

So I'm wondering ... should I simply bite the bullet and use the
Tcl_NewByteArrayObj(3) and friends to pass the objects as an associative
array of lists, or perhaps use the Tcl_NewDictObj(3) approach. Is there
any efficiency to be gained by using dicts over associative arrays at this
level (eg: conversion back and forth between C and Tcl)? Should I instead
do something else entirely? Has anyone done something similar?

Cheers,
Rob Sciuk
rob at controlQ dot com
---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
Jeff Hobbs

2007-12-20, 10:13 pm

On Dec 19, 10:30 am, s...@controlq.com wrote:
> In managing database objects, I use C based list objects which are similar
> to the old style (int argc, char **argv) of Tcl arg passing, and in
> addition, a form of "tagged list" which corresponds pretty closely to Tcl
> associative arrays, where each of the array elements are lists of the
> above kind, referenced by a "string" tag rather than a numerical index.
>
> I need to be able to pass data back and forth between the C interface to
> the database manager, and Tcl/TK for CRUD operations, and while I'd like
> to minimize the copying of data insofar as possible, however, portability
> is an issue, and I'd prefer to use published API's rather than try to use
> Tcl's internal structs to avoid this (I'd like this code not to break post
> 8.5.0).


If you get 8.5 as a starting point, use dicts, which have a complete C
and Tcl level set of APIs.

Jeff
spam@controlq.com

2007-12-21, 4:27 am

On Thu, 20 Dec 2007, Jeff Hobbs wrote:

> If you get 8.5 as a starting point, use dicts, which have a complete C
> and Tcl level set of APIs.
>
> Jeff
>


Thanks, Jeff ... that's what I thought, as the Dict() api's do look
complete and straightforward. I will proceed accordingly.

Cheers,
Rob Sciuk.
---- Posted via Pronews.com - Premium Corporate Usenet News Provider ----
http://www.pronews.com offers corporate packages that have access to 100,000+ newsgroups
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com