> The id of data items is the only way to refer to data items on the 
> protocol side. So I need a *weak association* between an id and the data 
> item (if any) of that id. I do not want to keep (in some ordinary Go map, 
> for example) the association between ids and their data items (otherwise, 
> no data item would be garbage collected). I accept the fact that eventually 
> (and perhaps quite later), a data item which is not reachable from the root 
> data item would be garbage collected.
>
> I was thinking of using unsafe.Pointer-s with runtime.SetFinalizer. A 
> simplistic approach could be to use a Go map (module variable) from pairs 
> of uint64_t to such unsafe pointers. At data item creation, I would 
> register in that map, using the pair of uint64_t-s as key, the pointer of 
> that data item suitably converted to an unsafe.Pointer. I would also pass 
> to SetFinalizer some finalization routine which would unregister (delete) 
> from that map. That scheme would work only if Go garbage collector does not 
> move objects (i.e. struct-s). If Go's GC is a conservative GC à la Boehm 
> GC <https://www.hboehm.info/gc/>, I'll probably even better "hide" the 
> pointer (e.g. by keeping not a Pointer, but some uintptr suitably 
> "hidden" e.g. by complementing all its bits à la GC_HIDE_POINTERS 
> <https://github.com/ivmai/bdwgc/blob/master/include/gc.h#L1299> in Boehm 
> GC). But that scheme would work only if Go's garbage collector is not 
> moving values (e.g. struct-s).* Is Go's garbage collector guaranteed to 
> be some marking *(not moving or generational copying, à la Ocaml) *one?* 
> FWIW, I am familiar with the terminology of the GC handbook 
> <http://gchandbook.org/>.
>

Why do you need this? 
You want the GC do the housekeeping for you, but I'm sure you won't be 
happy with the result, as the GC's policy differs from what you await...

What kind of eviction policy would you want?
Storing the data in an append-only file (or LevelDB), the deleted items in 
SQLite, evicting regularly and on close?

-- 
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.

Reply via email to