I’m developing a 2D infinite side scrolling game. As the player moves to the right, I continue to append a random segment of tiles to the world so that it’s seamless and “infinite”. As illustrated below, the random segment is appended when the right side of the viewport reaches the blue area.

The way I’m doing it currently works just fine. The problem is that I feel like there is a much more efficient way of doing it.
The world’s tiles are represented in a 2D array, and the function to append to the world looks something like this.
Array.Resize<Tile[]>(ref world.Tiles, newWidth);
for (int x = 0; x < newSegment.Width; x++)
{
world.Tiles[oldWidth + x] = newSegment.Tiles[x];
}
I understand that List<T> is ideal for a dynamic collection of objects, but keep in mind that there will be potentially thousands of columns. If I’m assuming this correctly, a lot of list items especially nested will yield a lot of overhead. For that reason I went with arrays initially.
Is my current approach inefficient? If so, how should I manage frequently (every 10-15 seconds on average) appending a random segment to the world?
How about a LinkedList
<T>? In your caseLinkedList<Tile>Or maybe even better, a Queue
<T>? A Queue might be the best for overhead if all you’re doing is Enqueue-ing Tiles and moving one direction (no need/ability to go to the previous tile(s).)With either collection, LinkedList or Queue, there is no need to resize an array, not yourself. Memory management is done internally and in an efficient manner.