Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

2 dimensional arrays

4 views
Skip to first unread message

harish...@gmail.com

unread,
Jun 9, 2005, 3:40:19 AM6/9/05
to
hi
i have read how in tcl we can use 2 dimensional arrays
like
set my_array(0,0) 6
set my_array(0,1) 3
...
or
array set my_array1 { 0,0 6 0,1 3}

both are different ways.
now suppose i have these values 6,3,... in a string variable
eg set my_string "6 3 ..."
i can set it to my_array in a for loop
but ,but
if i have my_string variable very big say 2048*512 (say)
then it will take long time to initialise in a for loop

so is there any other way by which i can optimise my time in
initialising array
can i initialise my 2-dimensional array through a string without for
loop

thankyou in advance

Arjen Markus

unread,
Jun 9, 2005, 4:31:06 AM6/9/05
to

Actually you have several options:

1. Tcl arrays are actually collections of variables. The names of the
elements are up to your discretion, there is no relation between
them.
You can therefore initialise only those elements you really need.

2. You can use list of lists, this comes closer to C or Fortran arrays.
Lists are more efficient (in terms of memory and access time), if
you have large amounts of data.

3. If you want to manipulate numerical data stored in arrays, consider
using an extension like NAP (<http://wiki.tcl.tk/nap). There are
others that give you similar functionality, but I have some
experience with this one.

Regards,

Arjen

harish...@gmail.com

unread,
Jun 9, 2005, 6:00:52 AM6/9/05
to
Thank you for your reply. I will definitely try the options suggested.
The actual purpose of my converting a string to Tcl array is I get this
big string from my C extension and I want to display it in a Tk Table.
As Tk Table can be directly linked to an Array I would like to convert
the string to a 2-dimensional Array.

thanks in advance

Arjen Markus

unread,
Jun 9, 2005, 6:41:03 AM6/9/05
to

In that case you will need an array indeed - Tktable expects an array

Regards,

Arjen

Robert Heller

unread,
Jun 9, 2005, 7:08:41 AM6/9/05
to
harish...@gmail.com,
In a message on 9 Jun 2005 00:40:19 -0700, wrote :

h> hi
h> i have read how in tcl we can use 2 dimensional arrays
h> like
h> set my_array(0,0) 6
h> set my_array(0,1) 3
h> ...
h> or
h> array set my_array1 { 0,0 6 0,1 3}

You do understand that this is not really a 2 dimensional arrays. In
Tcl an 'array' is not an indexed sequence of values (in the sense of C
arrays). A Tcl 'array' is really a hash table.

h>
h> both are different ways.
h> now suppose i have these values 6,3,... in a string variable
h> eg set my_string "6 3 ..."
h> i can set it to my_array in a for loop
h> but ,but
h> if i have my_string variable very big say 2048*512 (say)
h> then it will take long time to initialise in a for loop
h>
h> so is there any other way by which i can optimise my time in
h> initialising array
h> can i initialise my 2-dimensional array through a string without for
h> loop
h>
h> thankyou in advance
h>
h>

\/
Robert Heller ||InterNet: hel...@cs.umass.edu
http://vis-www.cs.umass.edu/~heller || hel...@deepsoft.com
http://www.deepsoft.com /\FidoNet: 1:321/153



0 new messages