On Wed, Feb 15, 2017 at 9:42 PM, Basile Starynkevitch <bas...@starynkevitch.net> wrote: > > On Wednesday, February 15, 2017 at 9:01:58 PM UTC+1, Tamás Gulácsi wrote: > >> >> 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 make you believe I won't be happy with the GC's policy. I'm quite open > on that. My understanding is that the GC's policy is what I want. >> >> >> 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? > > > Persistence to disk will only happen explicitly at shutdown (process exit) > time. So the file aspect don't matter much for my Q1. > > So my Q1 is basically: how can I make a weak hash table (in the sense I have > described, of having an association from strong keys -pairs of uint64- to > weak pointers to items).
Hi Basile. Go does not support any sort of weak pointer. You've already identified one approach using finalizers. That approach will work today as Go's garbage collector never moves items. There are no current plans to ever move items, but it is possible that some Go implementation will do so, in which case hiding the pointer as a uintptr will break. (By the way, Go's garbage collector is precise, so there is no need to invert the bits in the uintptr or anything like that--simply storing a pointer value in a uintptr is enough to hide it from the garbage collector.) Other than that, I think you will have to implement garbage collection yourself. That doesn't sound too hard with your data structure, which doesn't seem to have cycles. Basically traverse the data structure copying data from the current map to a new one, then replace the official map with the new one. With judicious locking this could even be done concurrently. Sorry I don't have anything else to suggest. Ian -- 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.