Jump to content
  • Advertisement


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


new and realloc

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

Allocate a new block of memory, copy the data across with memcpy or memmove, then delete the old block. Of course, this means that the addresses of the old and new blocks will be different. But needing to rely on the address being the same is not usually a very good design decision anyway.

Share this post

Link to post
Share on other sites
I've tested whether realloc actually works with new/delete, and it seems to do so for fundamental types (tested under the borland compiler). I haven't tested it with classes; that would involve having to manually call the constructors and destructors, which I'm not too interested in trying to do.

The easiest solution is, as you'll see:

#include <vector.h>


vector MyIntArray(5); // int array with initial size 5.
MyIntArray[50] = 8; // array grows in size as needed.

Edited by - Beer Hunter on August 13, 2001 4:19:50 AM

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!