hi,
i'm writing an external that requires a lot of memory freeing when it is destroyed, but i cant find much in the way of documentation telling me how to set up a deconstructor.
at the moment i'm doing this:
extern "C" __declspec( dllexport ) void markovchain_tilde_setup(void) { markovchain_tilde_class = class_new(gensym("markovchain~"), (t_newmethod)markovchain_tilde_new, (t_method)markovchain_tilde_destroy, sizeof(t_markovchain_tilde), CLASS_DEFAULT, A_GIMME, 0); class_addmethod(markovchain_tilde_class, (t_method)markovchain_tilde_dsp, gensym("dsp"), 0); }
with a deconstructor like this:
void *markovchain_tilde_destroy() { ....
but obviously this is no good because i need access to the dataspace struct. so how do i pass a reference to the struct to the deconstructor?
thanks, pete.
Peter Worth wrote:
hi,
i'm writing an external that requires a lot of memory freeing when it is destroyed, but i cant find much in the way of documentation telling me how to set up a deconstructor.
at the moment i'm doing this:
extern "C" __declspec( dllexport ) void markovchain_tilde_setup(void) { markovchain_tilde_class = class_new(gensym("markovchain~"), (t_newmethod)markovchain_tilde_new, (t_method)markovchain_tilde_destroy, sizeof(t_markovchain_tilde), CLASS_DEFAULT, A_GIMME, 0); class_addmethod(markovchain_tilde_class, (t_method)markovchain_tilde_dsp, gensym("dsp"), 0); }
with a deconstructor like this:
void *markovchain_tilde_destroy() { ....
but obviously this is no good because i need access to the dataspace struct. so how do i pass a reference to the struct to the deconstructor?
Declare the deconstructor as void markovchain_tilde_destroy(t_markovchain_tilde *x) and keep pointer(s) to the disposable memory somewhere in x. Martin
thanks, pete.
PD-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Martin Peach wrote:
Peter Worth wrote:
hi,
i'm writing an external that requires a lot of memory freeing when it is destroyed, but i cant find much in the way of documentation telling me how to set up a deconstructor.
at the moment i'm doing this:
extern "C" __declspec( dllexport ) void markovchain_tilde_setup(void) { markovchain_tilde_class = class_new(gensym("markovchain~"), (t_newmethod)markovchain_tilde_new, (t_method)markovchain_tilde_destroy, sizeof(t_markovchain_tilde),
[...]
}
with a deconstructor like this:
void *markovchain_tilde_destroy() { ....
hmm, why do you think that the free-method takes no arguments and is of type (void*)? i hope my oh-so-famous externals-howto does not claim such things:
"If memory is reserved dynamically, this memory has to be freed by the destructor-method _freemethod_ (without any return argument), when the object is destroyed."
Declare the deconstructor as void markovchain_tilde_destroy(t_markovchain_tilde *x) and keep pointer(s) to the disposable memory somewhere in x.
right.
btw, _please_ don't use the declspec constuction directly, as it will render your code unusable (without modifications) to non-M$VC compilers.
a far better approach would be to use conditional #define's
mfg.asder IOhannes