The C code is supposed to run on an embedded system, something like Arm CortexM or similar.
Two API interface designs are possible:
typedef struct { vars } t_object;
void init(t_object* p_object);
void run(t_object* p_object);
t_object my_object;
init( &my_object );
while(1)
run( &my_object );
or
typedef struct { vars } t_object;
t_object* init( );
void run(t_object* p_object);
void deinit(t_object* p_object);
t_object* p_my_object;
p_my_object = init( );
while(1)
run( p_my_object );
In the first case object is statically allocated on stack, and in the second case init()
dynamically allocates the object on heap.
What are the reasons to prefer one of the two ways in designing the interface?