I have a struct like this:
typedef struct {
int hi;
} my_struct;
Is there an advantage in using this:
my_struct *test = malloc(sizeof(my_struct));
test->hi = 1;
Instead of this:
my_struct test;
test.hi = 1;
I have a struct like this:
typedef struct {
int hi;
} my_struct;
Is there an advantage in using this:
my_struct *test = malloc(sizeof(my_struct));
test->hi = 1;
Instead of this:
my_struct test;
test.hi = 1;
No, usually it's quite the opposite. If you can use the format to satisfy your requrement
my_struct test;
test.hi = 1;
then it's always better, less overhead in runtime. There's no advantage in general of using memory allocator functions, when you can do without them.