How can I change the size of an array in C?

前端 未结 6 1112
灰色年华
灰色年华 2020-12-03 11:22

I am experimenting a little bit with gamestudio. I am making now a shooter game. I have an array with the pointer\'s to the enemies. I want. to when an enemy is killed. remo

6条回答
  •  一生所求
    2020-12-03 11:34

    As NickTFried suggested, Linked List is one way to go. Another one is to have a table big enough to hold the maximum number of items you'll ever have and manage that (which ones are valid or not, how many enemies currently in the list).

    As far as resizing, you'd have to use a pointer instead of a table and you could reallocate, copy over and so on... definitely not something you want to do in a game.

    If performance is an issue (and I am guessing it is), the table properly allocated is probably what I would use.

提交回复
热议问题