STRFREE/DISPOSE

Posted by Greven on Wed 14 Jan 2004 08:58 PM — 2 posts, 7,315 views.

Canada #0
Recently I've spent hours making sure that the STRALLOCs are consistant with the STFREE's, and the DISPOSE are consistan with str_dup. But I keep thinking that there has to be an easier way to do this. The best I can think is identifying if a string has links on it(ptr->links), but to do that I think you would need to be able to identify what kind of info is being passed.

I've also heard that c++ might make it possible to stop mis-matched functions, and since I've recently converted, that would be quite handy, heh. Any ideas?
USA #1
To make it error-proof you would need to have two separate data types.

For example a standard string (str_dup version) could be a pointer to a char* - just like it's supposed to be.

The hashed string (STRALLOC) on the other hand could be a pointer to a structure, like so:
struct HashedString
{
  char* str;
};


So you're just adding one level of code to it. Instead of doing ch->name, you'd do ch->name.str or something like that.

The cleanest way to do it however would probably be to migrate all the way to C++ style strings (STL) and make your own class for hashed strings. That's how I did it, in any case. :) And I find it to be oh-so-much nicer.