I am working with a Hashtable struct that maps keys to values, where the values are (void *) so that Hashtables can hold any kind of value.
To be able to free those values, the deconstructor of a Hashtable takes in a pointer to a freeing function as an argument. In my case, I know I am going to be freeing basic types, like char* and int*. Is it possible to pass in a pointer to the free() function, since this can deal with basic types?
Something like this:
FreeHashTable(hashtable_name, free);
You can (and should) pass to
freeevery pointer that has returned bymalloc, no matter which type (or struct) it points to. Be careful to not pass tofreepointers that you didn’t get from malloc. (Middle of arrays, local variables, etc)BTW, unless some of your data types need some work before freeing, you can do it without pass pointer to function – just call
free.