Thinking about how to make Go memory safe without using atomics everywhere: 1. Double bounds check slice indexing: i.e. store length of backing store on heap and check it. 2. Box interface types on heap. 3. Implement maps in Go with no unsafe. I think this works?
-
-
Alternate solution would be to make slices immutable and heap allocate them (i.e. if you set length, reallocate). This would probably want a generational GC of course to mitigate increased allocation pressure.
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I'm Go-n00b, can you explain the "double" aspect?
-
So slices are stored inline as (ptr, len, capacity) triples. This is not memory safe because if thread 1 is overwriting a slice value (ptrA, lenA, capA) to point somewhere else, there is a point in time which thread 2 could read (ptrB, lenA, capA).
- 9 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.