Yeah, I assumed it would work, but wanted to be sure. I'm trying to code a set of DMA structures like Stacks and Maps that people can put anything into, like Dynamic strings and other dynamically created stuff.
So when the structures are destroyed, the stuff in the structure is destroyed too, like:
int elem;
for each element i in structure
elem = ith element;
MemFree(elem);
next
MemFree(the actual DMA structure)
Ultimately, I want to be super sure my structures would be able to handle anything users put in, so they define their own destructor. A default one would be available that acts as if the structure contains just ints, no dynamic stuff. Sort of like:
int DMA_ELEM; // Represents each element in the structure.
void default_destroy() {}
void user_destroy()
{
// do to DMA_ELEM whatever you need to do to
// free it properly
}
.....
int myset = DMA_Set_create();
DMA_Set_SetDestructor(DMA_String_Create("user_destroy"));
.....
// Destructor loop...
string behaviour = DMA_String_ToNative( *PULL OUT OF STRUCTURE* );
for each element i in structure
DMA_ELEM = ith element;
CallFunction(behaviour)
next
MemFree(the actual DMA structure)