Increasingly in the past year I've been writing GC-aware code. On the one hand, my machine learning related stuff has sped up quite a fair bit. On the other hand additional profiling shows me how far I've yet to go. I've been thinking of moving a bunch of stuff off-heap. But at the same time, having come from a history of writing shitty C code, I know I need GC.
So my question is this - given a structure (an abridged version of the Dense tensor in Gorgonia) like this: type Dense struct { metadata *AP // Go allocated memory data unsafe.Pointer // off heap or otherwise inaccessible via Go l, c int // Go allocated memory } What happens when the GC scanner scans the data field? This trick was created to work with heterogenous memory (CUDA/GPU memory), and comes with a bag of flags to indicate if the memory is accessible or not. The thing about using CUDA is that the cycles are shortlived. The pattern goes like this: acquire, do operation, deallocate memory, invalidate all pointers, chuck the dense tensor into an object pool. This cycle has only been observed to happen between GC scan passes with CUDA memory. As such I have no idea what would happen if the GC scanner hits a unsafe.Pointer that it cannot access. Will the pointer be marked as unaccessible? Does it panic with SIGBUS? What are the long term implications of this, if say a separate memory pool were to be allocated outside. Some considerations: there are typically 200k of these *Dense tensors around in a small neural network that needs to be kept alive. It'd be preferable to not have the entire struct be allocated offheap, because that's definitely a sign of trouble to come. I'm aware that I can preallocate an arena of []bytes, and use it, but I'm currently weighting my options. Some advice would be quite nice. Please feel free to tell me I'm headed the wrong direction Thank you -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.