You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to define a custom function that will be called whenever allocated block is called ?
Motivation: I have existing project, where large objects with fixed arrays in them are allocated (objects can be >1mb). I would like to replace some of the fixed size array with malloced arrays. I hope to be able to attach custom free function to those objects, which will free the malloced arrays, when the main object is freed. I cannot change all the code base to replace the free, with ‘custom-free’ - to much work. I can fix the allocators - they are few of them.
Conceptually a destructor, similar to c++ delete or the gcc/clang cleanup attribute extension, for dynamically allocated memory.
Basically, I want to replace:
Struct big {
Double x,y,Z ;
Double a[1000000] ; // max value, but usually much smaller.
}
With:
Struct big {
Double x,y,Z ;
Double *a ; // max value, but usually much smaller.
}
allocator will be:
Struct big *alloc-big()
{
Struct big *p= callow(…);
Mi-set-free(p, free-big); // free big will be called when free(p) is called
P->a = calloc(actual size);
}
The text was updated successfully, but these errors were encountered:
Is it possible to define a custom function that will be called whenever allocated block is called ?
Motivation: I have existing project, where large objects with fixed arrays in them are allocated (objects can be >1mb). I would like to replace some of the fixed size array with malloced arrays. I hope to be able to attach custom free function to those objects, which will free the malloced arrays, when the main object is freed. I cannot change all the code base to replace the free, with ‘custom-free’ - to much work. I can fix the allocators - they are few of them.
Conceptually a destructor, similar to c++ delete or the gcc/clang cleanup attribute extension, for dynamically allocated memory.
Basically, I want to replace:
With:
allocator will be:
The text was updated successfully, but these errors were encountered: