Confirmed users
329
edits
| Line 130: | Line 130: | ||
* The structure containing the pointer is sometimes allocated on the stack, sometimes on the heap | * The structure containing the pointer is sometimes allocated on the stack, sometimes on the heap | ||
Also, persistent pointer updates may be subject to write barriers for incremental and/or generational GC, where any modification must be monitored to maintain various invariants. Basically, you can't add, remove, or change a heap-stored gcthing pointer without informing the GC about it. See | Also, persistent pointer updates may be subject to write barriers for incremental and/or generational GC, where any modification must be monitored to maintain various invariants. Basically, you can't add, remove, or change a heap-stored gcthing pointer without informing the GC about it. See https://developer.mozilla.org/En/SpiderMonkey/Internals/Garbage_collection for details. | ||
The simplest approach is to use HeapPtr<T> as the type of gcthing pointer fields. Any writes through a HeapPtr will trigger the needed barriers. There's also EncapsulatedPtr<T>, which is the same but different. Or RelocatablePtr<T>, which is different but the same. | The simplest approach is to use HeapPtr<T> as the type of gcthing pointer fields. Any writes through a HeapPtr will trigger the needed barriers. There's also EncapsulatedPtr<T>, which is the same but different. Or RelocatablePtr<T>, which is different but the same. | ||