Do you really need to store that many values?
Travis
var dim1=20;
var dim2=2;
var array=new[dim1];
for(var i=0;i<dim1;i++) {
array=new[dim2];
}
[/code]
So you actually create 21 arrays in this case. It's not cheap object wise (you just used 21 for just the array), and if you wanted to make it 100x2, you'd likely run out of objects.
So instead, what you can do is use 2 arrays:
var dim1=20;
var index0=new[dim1];
var index1=new[dim1];
In this case you only create 2 arrays, and if you change dim1 to 100, you still only have 2 arrays. [100x2] would use more memory, but not more objects.
Or, use just 1 array:
var dim1=20;
var array=new[dim1*2];
You have an array that's double the length needed (but only 1 array), and when you want to access values, (say at "idx"), they are in array at array[idx] and array[dim1+idx]. So from the first case that uses 21 arrays for a [20x2], you can use 1 array for a [20x2], and this may be something you'd really want to consider for something like a [20x20] array.
BTW: Sys.getSystemStats() - freeMemory, totalMemory,usedMemory in your code.
In the sim, the bottom line shows current usage, max available, and peak memory.I want to use a multidimensional array to test whether lines intersect. I was trying to implement some functions and I quickly ran out of memory, so it looks like I'm gonna have to conserve. I'm having a hard time understanding what the exact procedure would be to create arrays to work with.. like what code to type...
(1) in particular, how would I create an array of type "floats"?
(2) and could I save some memory by creating a const array at the start of my project to handle the "boundaries" which will not change throughout my program, i.e.,
static const points = [
2.74744, 9.37372,
8.36362, 8.22383,
7.32951, 3.38384,
2.02910, 4.29191
];
Can you post a link to an example or throw some code up for me to look at? There has to be some code in some of these forums pertaining to working with arrays...
(3) and, in terms of memory usage, is there a quick and dirty way to understand how much memory I have to work with, during run-time, for debug purposes? Something involving a GetSystemStats function?
I don't believe creating the array as a const has much impact on memory usage.