Biohazrd icon indicating copy to clipboard operation
Biohazrd copied to clipboard

Add support for runtime deletion of C++ objects

Open PathogenDavid opened this issue 3 years ago • 1 comments

In C++, deletion (as in the delete operator) and destruction (as in ~MyStruct) are separate concepts and are handled differently depending on the context.

In our current scheme, deletion is only required if you need to delete an object in C# which was allocated on the heap in C++.

We need to be careful of how we surface this, because the distinction here is not normally something most C++ developers worry about, much less C# developers. (The main distinction here is that objects are destroyed in C++ in different ways depending on whether they are allocated on the global heap, placed with placement new, or allocated on the stack. There's also concerns for how overloaded delete operators get called. Normally you only care about these things if you're using placement new, which is fairly niche and usually hidden behind macros.)

(Note to self: See notes for some details on how this is implemented in various ABIs.)

PathogenDavid avatar Feb 20 '21 11:02 PathogenDavid

(Note to self: See notes for some details on how this is implemented in various ABIs.)

I'm sure those notes are still somewhere, lol.

I ended up digging around quite a bit on the Microsoft ABI for destruction here:

https://github.com/MochiLibraries/Biohazrd/issues/243

PathogenDavid avatar May 06 '22 12:05 PathogenDavid