Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Hashtable free keys #65

Open
xfilesee opened this issue Sep 28, 2016 · 2 comments
Open

Hashtable free keys #65

xfilesee opened this issue Sep 28, 2016 · 2 comments

Comments

@xfilesee
Copy link
Contributor

xfilesee commented Sep 28, 2016

  • In configuration a free function specifically to free keys in hashtable_remove and hashtable_destroy cases can be added. In current configuration the keys are left in heap if they were dynamically allocated.
@srdja
Copy link
Owner

srdja commented Sep 28, 2016

Hey, thanks for opening an issue :-)

If I understand you correctly, you're saying that there should be a pointer to a free function kept in the hashtable structure that would be used to automatically free data when it's removed from the table?

If that's the case, I think it is probably a good idea to add an option for that. Although I think it might be better to do it with a callback function instead of adding another field to the structure. You might want to take a look at this related issue.

@xfilesee
Copy link
Contributor Author

Thanks for the answer.
I needed a solution immediately so I added 2 function pointers to both struct hashtable_s and hashtable_conf_s:
table->key_free
table->value_free
By default NULL is assigned to both of these functions (to match the current configuration) and before calling I always check to make sure they are not NULL: like in hashtable_remove function:
if(table->key_free != NULL)
table->key_free(key);

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants