Jump to content
  • Advertisement
Sign in to follow this  
lincsimp

Copying arrays

This topic is 4848 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 Whats the fastest way to copy an array (in c++) of floats? I know you can just have a for loop and go through everything... Can you copy the chunk of memory? cheers

Share this post


Link to post
Share on other sites
Advertisement
You should really use std::copy() for your copying needs in C++. However, if all you are concerned about is speed, for copying an array of floats you might consider using memcpy(), especially if your compiler uses function intrinsics for memcpy().

Share this post


Link to post
Share on other sites
And aligning them to a 32-bit boundary should also make a smidge faster.

Share this post


Link to post
Share on other sites
For an array of floats, you can use memcpy:

float *pTargetArray = new float[iArraySize];
memcpy(pTargetArray, pSourceArray, (sizeof(float) * iArraySize));

Don't try this with non-built in types.

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!