D
drhowarddrfine
I'm unsure the best way to do this. I want to call a function that
will generate a string to be used by the calling routine. Where is
the best place to store that string? iow:
1) Should I set aside an array in the calling routine and have the
function strcpy to that?
routine(){
char string[16];
called_function(string);
}
called_function(char* string){
strcpy(string,"string");
}
2) Make the string area static for the calling routine?
routine(){
char *string_pointer;
string_pointer=called_function();
}
char* called_function(char* string){
static char string[16];
strcpy(string,"string");
return string;
}
3) Make the string area global to that file?
char string[16];
calling_routine(){called_function();}
called_function(){strcpy(string,"string");}
Part 2 of this would be, I have a whole bunch of these small routines
that need less than 256 bytes of memory for storing such strings.
Would it be better to just malloc to acquire the memory for that and
then release it? Does that cause relative program slow down doing all
that acquire/releasing?
will generate a string to be used by the calling routine. Where is
the best place to store that string? iow:
1) Should I set aside an array in the calling routine and have the
function strcpy to that?
routine(){
char string[16];
called_function(string);
}
called_function(char* string){
strcpy(string,"string");
}
2) Make the string area static for the calling routine?
routine(){
char *string_pointer;
string_pointer=called_function();
}
char* called_function(char* string){
static char string[16];
strcpy(string,"string");
return string;
}
3) Make the string area global to that file?
char string[16];
calling_routine(){called_function();}
called_function(){strcpy(string,"string");}
Part 2 of this would be, I have a whole bunch of these small routines
that need less than 256 bytes of memory for storing such strings.
Would it be better to just malloc to acquire the memory for that and
then release it? Does that cause relative program slow down doing all
that acquire/releasing?