[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ extension and garbage collection



> The garbage collector's (Boehm-Demers-Weiser?) mark algorithm
> must know about MrEd's C++ objects.  How?  Does it start with
> the BSS space and just follow every four byte boundary as if it
> were a pointer? 

Yes,

> Can I do something in my C++ code to inform the GC about my objects,
> so that they aren't collected?

You can write

 inline void *myclass::operator new(size_t size)
 {
    return malloc(size);
 }

 inline void myclass::operator delete(void *p) 
 {
    free(p);
 }

For each class like "myclass". Some compilers distinguish regular new
from new on an array of myclass objects:

  inline void *myclass::operator new[](size_t size) {
    return malloc(size);
  }

But that doesn't solve the problem when you use `new' on structs (if
any) or arrays of integers.



Matthew