Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

billybob

any reason why this wouldn't work?

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

inline void * MyRealloc(void * Mem, long size) { char * temp = new char[size]; memcpy(temp, Mem, size); delete [] Mem; return (void*)temp; } something isn''t working, and i suspect its this, so i want to rule it out as a possible cause. pretty simple, if anything i think its the delete [] Mem, but i''m not sure.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
you are copying "size" bytes from the old array to the new, that means that the new array must be smaller or equal to the old array, or the program will missbehave.
that is prolly not what you want

Share this post


Link to post
Share on other sites
Assuming the new array is larger than the old, it will only read from outside the old array, not write, so you won''t mess up other things. However, reading outside an array is as much no-no as writing outside it. You''re not guaranteed to have read access outside that array. It may work sometimes, sometime it may not, so you better make it right from the beginning.

Share this post


Link to post
Share on other sites
I have something like this in my program too. Try this:

inline void * MyRealloc(void * Mem, long old_size, long new_size)
{
// take the smaller size of the 2
long copy_size = new_size >= old_size ? old_size : new_size;
char * temp = new char[size];
memcpy(temp, Mem, copy_size);
delete [] Mem;
return (void*)temp;
}


I think this is right... tell me if its wrong so I can fix mine

thanks

Share this post


Link to post
Share on other sites

  • 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!