Advertisement Jump to content
Sign in to follow this  
lincsimp

Copying arrays

This topic is 4914 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.

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!