Jump to content
  • Advertisement
Sign in to follow this  
Gage64

Access violation - why? [Solved]

This topic is 3713 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 two arrays of pointers to integers, arr and result. I need to copy size elements from result to arr, starting from low. If I do this:
memcpy(arr + low, result, sizeof(int*) * size);
it works fine, but if I do this:
for (i = low; i < low + size; ++i)
    arr = result;
I get an access violation when I later try to dereference one of the pointers in arr. I thought the loop does the same thing as the call to memcpy(), but looks like I was wrong. What is the difference between the two? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Gage64
I thought the loop does the same thing as the call to memcpy(), but looks like I was wrong. What is the difference between the two?


memcpy reads from result[0] to result[size-1], whereas the loop reads from result[low] to result[low+size-1].

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
memcpy reads from result[0] to result[size-1], whereas the loop reads from result[low] to result[low+size-1].


I can't believe I missed that...

Thank you.

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!