C dynamically growing array

前端 未结 7 2110
闹比i
闹比i 2020-11-22 07:57

I have a program that reads a \"raw\" list of in-game entities, and I intend to make an array holding an index number (int) of an indeterminate number of entities, for proce

7条回答
  •  不要未来只要你来
    2020-11-22 08:25

    When you're saying

    make an array holding an index number (int) of an indeterminate number of entities

    you're basically saying you're using "pointers", but one which is a array-wide local pointer instead of memory-wide pointer. Since you're conceptually already using "pointers" (i.e. id numbers that refers to an element in an array), why don't you just use regular pointers (i.e. id numbers that refers to an element in the biggest array: the whole memory).

    Instead of your objects storing a resource id numbers, you can make them store a pointer instead. Basically the same thing, but much more efficient since we avoid turning "array + index" into a "pointer".

    Pointers are not scary if you think of them as array index for the whole memory (which is what they actually are)

提交回复
热议问题