I need to use thread-local storage in a cross-platform project. In section * IX, I use pthreads and can avoid memory leaks thanks to a good pointer to the destructor function passed as the second argument pthread_key_create, but on Windows TlsAllocthere is no such thing. I also cannot find a common place where any function is called when the stream exits (otherwise, I would run a list of function pointers that are called when the stream exits).
Be that as it may, it seems that I basically have a situation where for the actual use of streaming local storage I need to allocate my own space on the heap and pass a pointer to it TlsSetValue, but if the stream exits ... I have no way to ensure memory is freed (except those who explicitly call TlsGetValueand delete/ free/ HeapFree/ etc at the end of the stream function.
Does anyone know a better way?
source
share