M
MJL
I am working on a small project that involves the manipulation of
dynamically allocated memory for strings. I was wondering why the
string.h functions are the way they are and why not as follows:
mystrcat(char** s1,char** s2);
where s1's memory allocation can now be handled inside of the function
and s2 can be freed and pointed to NULL inside the function.
I'm not saying the built in functions are not useful as they are, but
this seems to be a simple way to hide away some of the messy memory
management statements.
char *s1,*s2;
assignstrings(&s1,&s2);
mystrcat(&s1,&s2);
dostuff(s1);
free s1;
see, not a single visible malloc statement and only one string to free
at end. Of course the functions would have to be well documented for
the use of others.
dynamically allocated memory for strings. I was wondering why the
string.h functions are the way they are and why not as follows:
mystrcat(char** s1,char** s2);
where s1's memory allocation can now be handled inside of the function
and s2 can be freed and pointed to NULL inside the function.
I'm not saying the built in functions are not useful as they are, but
this seems to be a simple way to hide away some of the messy memory
management statements.
char *s1,*s2;
assignstrings(&s1,&s2);
mystrcat(&s1,&s2);
dostuff(s1);
free s1;
see, not a single visible malloc statement and only one string to free
at end. Of course the functions would have to be well documented for
the use of others.