Reputation: 6731
The information that i have found on the internet for this is not explained very well. I would like to know how to go about implementing a 2-D array of double-precision floating point numbers. I would like the dimensions of the array to be variable so if I say .double 100, then I am wasting a lot of memory because that may not be the size of the array e.g. could be 5 x 5. Would I have to use the stack to solve this problem? Or how else could I go about it? Also if someone could explain how to efficiently fill the array it would be much appreciated!
Upvotes: 1
Views: 5354
Reputation:
You can implement any rectangular 2D array as 1D array using row-major order, the only different would be is in calculating the address of the element.
For example if you have a 3×5 array of double
's and you want to access the element array[x][y]
, you can calculate its address using the formula:
address of array[x][y] = base of array + 8 * (5 * x + y)
where base of array
is the base address of array
or array[0][0]
, 8
is the size of an element sizeof(double)
and 5
is the number of columns.
Upvotes: 2