Put stores a value in the map. It can later be retrieved using Get. It must be removed using Remove to avoid memory leaks.
(v interface{})
| 19 | // Put stores a value in the map. It can later be retrieved using Get. It must |
| 20 | // be removed using Remove to avoid memory leaks. |
| 21 | func (m *refMap) Put(v interface{}) unsafe.Pointer { |
| 22 | m.lock.Lock() |
| 23 | defer m.lock.Unlock() |
| 24 | if m.refs == nil { |
| 25 | m.refs = make(map[unsafe.Pointer]interface{}, 1) |
| 26 | } |
| 27 | ref := C.malloc(1) |
| 28 | m.refs[ref] = v |
| 29 | return ref |
| 30 | } |
| 31 | |
| 32 | // Get returns a stored value previously inserted with Put. Use the same |
| 33 | // reference as you got from Put. |