Looking through lots of code, I've noticed that there seems to be a waste of memory in lots of places. Not nessecarily leaks, but just wastes.
For example, CHAR_DATA has many of its fields initialized with STALLOC(""); and str_dup("");. This is needed, of course, to make sure that there is memory, even with an empty string, in the fields so if they are accesses, you will not crash. However, this memory is rarely freed before having its pointer changed to whereever the memory from the fread_string or fread_string_nohash is. This then seems to be lost memory.
When using fread_string, it is much less of a problem than with fread_string_nohash, because all the "" take up one block of memory, but nohashed string will just be taking up extra memory.
As a point, I enter "memory check greven", and this is the appropriate data output:When I do "memory check", checking the empty string, I get: This is not nessecarily bad, but its not good, since there must be lots of memory wasted on str_dup, assuming that you haven't changed all strings to STRALLOC/STRFREE.
I have thought of 2 seperate way that this might be handled:
One, is use a different form of fread_string, perhaps fread_string_free(FILE *fp, char **string) and fread_string_nohash_free(FILE *fp, char **string), where it does not return anything, but has "if ( *string ) STRFREE(buf)" and the str_dup equivalent, and uses "*string = STRALLOC( *string );return" instead of "return STRALLOC(string);"
The other idea I had was a little different, and would probably take more work, I dunno. This would be to use 2 different KEY macros, since this is used in the majority of file reading(except areas, I know), perhaps KEYH and KEYN, something like:
However, all these ideas need the coder to be very strict making sure they have corresponding STALLOC/fread_string and str_dup/fread_string_nohash.
Just a thought while I'm bored, and flaws/input on this idea?
For example, CHAR_DATA has many of its fields initialized with STALLOC(""); and str_dup("");. This is needed, of course, to make sure that there is memory, even with an empty string, in the fields so if they are accesses, you will not crash. However, this memory is rarely freed before having its pointer changed to whereever the memory from the fread_string or fread_string_nohash is. This then seems to be lost memory.
When using fread_string, it is much less of a problem than with fread_string_nohash, because all the "" take up one block of memory, but nohashed string will just be taking up extra memory.
As a point, I enter "memory check greven", and this is the appropriate data output:
Hash info on string: greven
Links: 3 Position: 53/291 Hash: 6 Length: 6Hash info on string:
Links: 38791 Position: 1/1 Hash: 0 Length: 0I have thought of 2 seperate way that this might be handled:
One, is use a different form of fread_string, perhaps fread_string_free(FILE *fp, char **string) and fread_string_nohash_free(FILE *fp, char **string), where it does not return anything, but has "if ( *string ) STRFREE(buf)" and the str_dup equivalent, and uses "*string = STRALLOC( *string );return" instead of "return STRALLOC(string);"
The other idea I had was a little different, and would probably take more work, I dunno. This would be to use 2 different KEY macros, since this is used in the majority of file reading(except areas, I know), perhaps KEYH and KEYN, something like:
#define KEYH( literal, field, value ) \
if ( !str_cmp( word, literal ) ) \
{ \
if ( field ) \
STRFREE( field ); \
field = value; \
fMatch = TRUE; \
break; \
}
#define KEYN( literal, field, value ) \
if ( !str_cmp( word, literal ) ) \
{ \
if ( field ) \
DISPOSE( field ); \
field = value; \
fMatch = TRUE; \
break; \
}However, all these ideas need the coder to be very strict making sure they have corresponding STALLOC/fread_string and str_dup/fread_string_nohash.
Just a thought while I'm bored, and flaws/input on this idea?