What is the best way to handle an output struct with some strings in it ?
struct info
{
wchar_t * text;
size_t text_len;
}
void Foo(struct info * output);
User need to allocate text himself
output can be recycled in a loop
hard to know how much memory needs to be allocated, possible waste of memory if output is to be stored (eg. keeping a list a items)allocate the text within Foo
a pain for the user to free output, since he has to free each text before (can make a FreeStructInfo to ease the pain)
not so good within loopsallocate output from within Foo
Foo can embed text within struct info and user need only free output to free all.
good for storage (Foo knows how much it needs to allocate),
but maybe a lot of stress for memory if used as a shortlived variable in a loop since it can't be recycled.
Windows uses the "User need to allocate text himself" and either you allocate enough or you need to call the function twice to get the size needed.