pointers?

Started by
7 comments, last by Spoonbender 18 years, 3 months ago
i have an array of some data for eg char buffer[256]; for my keyboards state, and i have an other array for a structure struct { pointer to some function; char key; // the key which refers to buffer[] }; so is it better for performance to use in struct char key; or char * key; and then point to some char in buffer[]?
Advertisement
Moved to General Programming.
I dont understand what your asking exactly, but performance shouldnt really be a big difference. If your asking what im thinking, then the pointer would be better.
i'm asking would it be better to use a pointer to buffer[]

char * ch; or char ch; and then buffer[ch] or *ch with pointer
I wouldn't care about performance with regards to this. Use the method that is least error-prone and easiest to use and maintain. Worry about performance only where it makes sense, e.g. algorithms, data structures and bottlenecks identified through profiling the application.
In your case I would stick to an integral index instead of a pointer.

HTH,
Pat.

PS: Using an int instead of a char would improve performance on some platforms. Intel suggest avoiding pointer arithmetic and use indices instead, btw. I don't have the link to that article, though [smile]
Not much performance difference there but the way I would do it is make a pointer to your buffer pointer

EDIT: BEATEN! :-p
there is not much to performance here but i'm thinking of the theory that i could use in bigger problems
Quote:Original post by mirza101
there is not much to performance here but i'm thinking of the theory that i could use in bigger problems

With this sort of scenario, there is no theory you can use in bigger problems. Each problem has to be approached on its own merits.

CM
The only general "theory" you can get out of this is as darookie said, that using array notation instead of pointer arithmetics is recommended by both AMD and Intel.

This topic is closed to new replies.

Advertisement