There are lots of standard solutions for that problem.

For an array, you could use either a counter, or a function that checks for the next empty space in the array. This is however a bad solution.

However the usual way is not an array, but a linked list. While an array has a fixed size, a linked list can have any size and you can easily append or remove nodes without the need to look for an empty space. Predefined objects like PANELs, BMAPs etc. are stored in linked lists.