C++ equivalent of realloc ?

This is a discussion on C++ equivalent of realloc ? within the C++ Programming forums, part of the General Programming Boards category; How do i re-allocate an array in C++ ? equivalent of realloc ?...

I saw your other post and i would suggest that if speed is of the essence that you overload new[] and delete[].In your new new operator use global new to give you a largish chunk of memory and then you can yourself split that into chunks maybe stored in a list or a map and do the memory allocations yourself. I think a call to a function over a call to global new will give you the efficiency you are after.

If this is in regards to your array question you posted in Gaming, I suggest you take my earlier advice and use a doubly linked list, not an array -- an array is just not a good move for what you're doing. It's much slower than a doubly linked list in all resizing, no matter how you implement it.

Hey,
I know using arrays this way, would slow down the loading of data (world,objects etc.). But that's only done once in the beginning.

After the data has been loaded into the arrays it can be traversed directly.
However, on the other hand, if i use a linked list, it would require linear traversal causing a major slowdown. (traversing all entries before the required one).

If you are just going to process a list of objects every frame or something of that nature, it's not as though you need to process the 31st object before you process the 16th, so if you traverse in order and process each in that order, any container you use will give you O(N) access.

Think of them like a pawn and queen on a chessboard, moving in one column from one side of the board to the other. The pawn, in one step, can only move one square, while the queen can move to any of them in a single move. If you need to hit the squares in a random order (like, 7, 3, 1, 6, 4, 5, 8, 2) the queen is much faster than the pawn. If you plan to hit them in the order 1, 2, 3, 4, 5, 6, 7, 8, each is equally fast. And so it is with arrays and linked lists.