segmentation fault - Why does Matlab crash when I use delete[]? -
i'm writing 2 matlab mex file handle persistent memory. want this
a *a = new a[n];
and free memory when i'm done using
delete[] a;
this done using 2 separate mex function calls. problem delete[] statement crashes matlab segmentation fault. however, if reserve memory using malloc works fine:
a *a = (a *) malloc(n*sizeof(a)); = new(a) [n];
and when i'm done
free(a);
any ideas why happens? proper way deal situation?
edit: looking @ code realize wasn't telling truth above. doing like
a *a = new b[n];
and then
delete[] a;
where b derived a. have found out results in undefined behaviour...
Comments
Post a Comment