Alglib 2d array

I'm a bit confused about using the setlength() function of real_2d_array in alglib. Below is a code example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main() {

	using namespace alglib;
	int s=3, t=5, i, j;
	real_2d_array fmatrix;
	fmatrix.setlength(s,t);
	for(i=0;i<s;i++) {
		for(j=0;j<t;j++) fmatrix[i][j]=i+j;
	}
	for(i=0;i<s;i++) {
		for(j=0;j<t;j++) cout << fmatrix[i][j] << "  ";
		cout << endl;
	}
	


	return 0;
}


Running this, I get (as expected):

1
2
3
0  1  2  3  4
1  2  3  4  5
2  3  4  5  6


But if I switch around s and t in setlength (making it fmatrix.setlength(t,s) ), instead of getting a segmentation fault or something, I get

1
2
3
0  1  2  3  1
1  2  3  4  2
2  3  4  5  6


Does anyone know what's going on here? is the last column (1,2,6) completely random and unspecified?
Last edited on
actualy, the last 2 colums should be random, becouse you make this:
0|1|2 (somewhere)3|4
1|2|3 (somewhere)4|5
2|3|4 (somewhere)5|6
| |
| |
Topic archived. No new replies allowed.