Get the latest tech news
Cheating the Reaper in Go
Even though I am a C++ programmer at heart, Go fascinates me for none of the reasons you think. Go has made several interesting design decisions: - It has virtually no Undefined Behavior1.
This makes our New API unsafe, especially since Go does not provide a standard constraint for marking generic parameters as pointer-free: unsurprisingly, the don’t expect most users to care about such a detail. This arena would not need to go into the GC to request new chunks, re-using the ones previously allocated (and potentially saving on the cost of zeroing memory over and over again). HerewecanmakeuseofanimportantpropertyofhowGo’sGCworks:anypointerintoanallocationwillkeepitalive,aswellas anythingreachablefromthatpointer.Butthechunkswe’reallocatingare[]uintptr s,whichwillnotbescanned.Iftherecould somehow beasinglepointerinthisslicethatwasscanned,wewouldbeabletostickthepointer a*Arena there,andsowhenanythingthat Alloc returnsisscanned,itwouldcause a tobemarkedasalive.
Or read this on Hacker News