K
Kevin
Hi all,
I clearly have an issue with some pointers, structures, and memory
allocation. Its probably pritty basic, but I'm a little stuck. Any
help would be greatly appreciated.
I'd like to instantiate an arbitrary number of arrays of arbitrary
size in function_a, copy the pointers, store the data, and free any
unused memory. My basic structure is as follows:
I have two structs
typedef struct {unsigned char * data;} type_a;
typedef struct {unsigned char * data;} type_b;
void main
{
type_a * ptr_a;
type_b * ptr_b;
ptr_a = malloc(sizeof(type_a));
for (*some runtime count*)
{
ptr_b = malloc(sizeof(type_b));
set_function(ptr_a);
ptr_b->data = ptr_a->data;
store_function(ptr_b);
}
free(ptr_a);
}
void set_function (type_a * ptr)
{
type_a->data = malloc(*some runtime size*);
}
I of course check for the null returns on the malloc calls but am
pritty sure I have more fundamental issue as to why this isn't
working. I am also purposely not freeing ptr_b as this is what is
actually getting stored. Please let me know if what I'm attempting to
do isn't clear. Again, thanks for any help.
Regards,
Kevin
I clearly have an issue with some pointers, structures, and memory
allocation. Its probably pritty basic, but I'm a little stuck. Any
help would be greatly appreciated.
I'd like to instantiate an arbitrary number of arrays of arbitrary
size in function_a, copy the pointers, store the data, and free any
unused memory. My basic structure is as follows:
I have two structs
typedef struct {unsigned char * data;} type_a;
typedef struct {unsigned char * data;} type_b;
void main
{
type_a * ptr_a;
type_b * ptr_b;
ptr_a = malloc(sizeof(type_a));
for (*some runtime count*)
{
ptr_b = malloc(sizeof(type_b));
set_function(ptr_a);
ptr_b->data = ptr_a->data;
store_function(ptr_b);
}
free(ptr_a);
}
void set_function (type_a * ptr)
{
type_a->data = malloc(*some runtime size*);
}
I of course check for the null returns on the malloc calls but am
pritty sure I have more fundamental issue as to why this isn't
working. I am also purposely not freeing ptr_b as this is what is
actually getting stored. Please let me know if what I'm attempting to
do isn't clear. Again, thanks for any help.
Regards,
Kevin