Hi Sparsh,
if the dimensions are constant, the field can be assigned at the same
time it is declared, i.e.
public class MyClass {
static gridSize = 100;
static gridInfo = new Array[double]((0..gridSize)*(0..gridSize), 0);
public static def myFunc(myNumber:int) {
// access gridInfo here
}
}
Where possible, it is better to assign fields in this way, in line with
the 'Avoid specifying explicit types' principle (see
http://x10-lang.org/documentation/practical-x10-programming/performance-tuning.html).
By the way - does myFunc need to be a static method? If not, the same
would work with a regular instance val field, i.e.
...
val gridInfo = new Array[double]((0..gridSize)*(0..gridSize), 0);
public def myFunc(myNumber:int) {
// access gridInfo here
}
...
Cheers,
Josh
On 05/02/13 04:25, Sparsh Mittal wrote:
Hello
Thanks for previous reply, by which I was able to write the program
using 2D array.
In another program, I need to declare a 2D square array, which I need
to access in multiple functions of the class. The overall structure is
here:
/public class MyClass {
//I think I have to declare gridInfo here. It would be 2D array and
used in myFunc.
public def this() {
////Should I allocate gridInfo here?
////val gridInfo = new Array[double]((0..gridSize)*(0..gridSize), 0);
}
public static def myFunc(myNumber:int) {
// I need to use gridInfo here
}
public static def main(args: Array[String](1)) {
//Or Should I allocate gridInfo here?
}
}/
Would you please tell me how should I declare and allocate gridInfo
array? The dimensions are already known (constant).
Thanks for your help.
Thanks and Regards
Sparsh Mittal
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users