Jump to content
  • Advertisement
Sign in to follow this  
mirza101

pointers?

This topic is 4608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[]?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Not much performance difference there but the way I would do it is make a pointer to your buffer pointer

EDIT: BEATEN! :-p

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!