I have a struct that has space for unsigned ints:
typedef struct {
unsigned int *arr;
} Contents;
When I allocate memory:
Contents *Allocator()
{
Contents *cnt = malloc(sizeof(Contents));
cnt->arr = calloc(1, sizeof(unsigned int));
}
I later retrieve it by dereferencing it by passing in a pointer to Contents and doing:
void SomeFunction(Contents *cnt)
{
unsigned int * arr = cnt->arr;
arr[0] >>= 1; // In the future 0 will be replaced by a loop over the array items
cnt->arr = arr;
}
Once I exit out of the function, cnt->arr becomes empty. Do I have to do a memcpy? Am I not understanding how the struct is laid out? As I understand
cnt->arr = (*cnt).arr
Thanks!