I have the following object array:
typedef struct MyStack {
size_t size; // current size of stack
size_t max; // max size of stack
Item* stack[];
} MyStack;
And I want to create a stack of ten items, so I do:
MyStack stack = malloc(sizeof MyStack);
stack->size = 0;
stack->max = 10;
stack->stack = malloc(sizeof Item * 10);
Then let's say I fill up the stack -- and I have ten items in it. I want to resize the stack to 15 items. What would be the way to do this, including, obviously copying over the existing 10 items to the new stack? Does the problem by definition mean that at one point in memory I'll have 25 items allocated? (not important here, but I could imagine if someone has a data structure of 2GB and they need to resize it, it could lead to a lot of issues).