Home > Archive > Tcl > June 2005 > 2 dimensional arrays
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 |
2 dimensional arrays
|
|
| harish.dewan@gmail.com 2005-06-09, 8:58 am |
| 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 2005-06-09, 8:58 am |
| harish.dewan@gmail.com wrote:
>
> 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
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.dewan@gmail.com 2005-06-09, 8:58 am |
| 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 2005-06-09, 8:58 am |
| harish.dewan@gmail.com wrote:
>
> 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
In that case you will need an array indeed - Tktable expects an array
Regards,
Arjen
| |
| Robert Heller 2005-06-09, 4:00 pm |
| harish.dewan@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: heller@cs.umass.edu
http://vis-www.cs.umass.edu/~heller || heller@deepsoft.com
http://www.deepsoft.com /\FidoNet: 1:321/153
|
|
|
|
|