Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

c++. What am I doing wrong with this memcpy of a float ** variable?

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

Hi im using c++, and I'm trying to memcpy a float ** var to another float ** var2 eg:
float **var = new float*[3];
float **var2 = new float*[3];

for(int i=0;i<3;i++) {
   var = new float[2];
   var2 = new float[2];

   for(int j=0;j<2;j++) {
      var[j] = i+j;
      var2[j] = 0;
   }
}

memcpy(var, var2, sizeof(float)*3*2);
//and i delete them later..



But it crashes when I try to memcpy, saying:
Quote:
First-chance exception at 0x004120d1 in NnBack.exe: 0xC0000005: Access violation reading location 0x00000008. Unhandled exception at 0x004120d1 in NnBack.exe: 0xC0000005: Access violation reading location 0x00000008.
What am I doing wrong here? Thankyou.

Share this post


Link to post
Share on other sites
Advertisement
You're trying to memcpy() as if the arrays were regular 3x2 arrays, with each element right after another, but since you're declaring everything dynamically, that's not how they really are.

Share this post


Link to post
Share on other sites
Generally, the code to copy, or free your array is going to be about as complicated as the code to create it. Alarm bells should be ringing otherwise.

If you want to memcpy it as an array of 6 floats then declare it as an array of 6 floats.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!