Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing pointer to array

Status
Not open for further replies.

dd007

Technical User
Jan 7, 2003
7
US
I have a 2dimensional array and I only want to pass one row to a function. The array is setup as:
myArray[4][8];

I call the function:

status = functionx(myArray[j]); where j is the row

Fuction Prototype:
short functionx(short *myArray);

Function:
short functionx(short *myArray)

Is this correct? The program is very cpu intense and I trying to get all the performance out of the code as possible. I did not see much gain by changing the code
to use pointers. Just checking to see if I wrote the code correctly.

Thanks
 
At first glance, that seems ok to me.

If you're trying to get all the performance possible, why not use a 1-dimensional array and do a little math? My understanding has always been that mathematical operations were quicker than array index manipulations.

For example:
int My1Array[9];

could really be the same as

int My2Array[3][3];

and

My1Array[row*3];

would be faster than

My2Array[row][0];

...at least, that's what I was always taught. Someone correct me if this isn't the case.

Ben
A programmer was drowning. Lots of people watched but did nothing. They couldn't understand why he yelled "F1!"
 
dd007, strictly speaking, it's OK if myArray base type is short.
No need to excuse a pointer usage. We all on the C/C++ board, it's splendid!...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top