Jump to content
  • Advertisement
Sign in to follow this  
yuppies

questions about array

This topic is 4445 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

how is array represented in the memory or in stack? i got an argument from a japanese manager of mine saying that accessing of array using its index is verry slow since in actual representation(in ASM or in Memory/Stack) the array is traversed in memory before reaching the right index. Is this true? :) What are my options if these is true? what other data struct way is fast in accessing and storing value aside from "direct" access from an array. I just need some idea before i argue my boss :)

Share this post


Link to post
Share on other sites
Advertisement
An array access is just a pointer addition and a dereference. It's slightly slower than accessing a variable normally, but only by a few clock cycles. Unless you're doing millions per frame, it's not going to be a problem. And if you access array index zero, it's just a pointer dereference.

It's laid out in memory as one contiguous block of memory, it doesn't get "traversed" for each access. Access is O(1).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I guess your manager is confusing arrays with linked-lists...

Share this post


Link to post
Share on other sites
An array is represented in memory by a single continuous block of memory, the size of which is equal to the size of one array element * the number of elements in the array. Array access is achieved by taking the address of the array and adding an offset to it.

You boss seems to be thinking of a linked list, where to access an element you have to access every element in front of it in the list sequentially.

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!