Click here to Skip to main content
15,890,123 members

Comments by firmwaredsp (Top 2 by date)

firmwaredsp 25-Oct-10 2:22am View    
<There is no need to know the dimensions at compile time./>

The code snippet below works. It is my interpretation of what you posted. But you have to know ahead of time the value of 'n' in the statement 'double* p5[n]', which in the below case is 4. If 'double* p5[nRow]' is used, an error will be generated. 'nRow' is passed to this function at run time.



void PinnedArray (array<double, 2="">^ numbers, const int nRow, int nCol)
{
// This method works if I know at compile time how many rows are required.
pin_ptr<double> p1 = &numbers[0,0];
pin_ptr<double> p2 = &numbers[1,0];
pin_ptr<double> p3 = &numbers[2,0];
pin_ptr<double> p4 = &numbers[3,0];

// Note: This will generate an error.
// double* p5[nRow];

int n = 4;
double* p5[n];
p5[0] = p1;
p5[1] = p2;
p5[2] = p3;
p5[3] = p4;
double** pp = p5;

NativeCode(pp, nRow, nCol);
}
firmwaredsp 24-Oct-10 20:05pm View    
Nishant, thanks for posting your code.


Your solution works if you know at compile time the dimensions of your array. I came up with a solution that will allow a user to enter the array dimensions at run time. I want to post my code. Unfortunately, this blasted editor has a mind of its own and adds symbols. If you tell me how you posted your code without the unwanted symbols, I will then post mine so as to help someone in need in the future.

i.e void Nishant_PinnedArray (array&lt;double, 2&gt;^ numbers, const int nRow, int nCol)