Looking for a little insight on if it is possible to do something:

Given this type:

type Blah struct {
    Payload []byte
}

What I'm looking for is to kick off a finalizer when a slice and all other 
slices backed by the same array get GC'd. 

In lieu of that, whenver the pointer to the array backing a slice get's 
GC'd. I realize that in this case, the slice actually may stay around when 
the array is GC'd because an append creates a new array on the slice.

I don't think the first is possible, as you can't call SetFinalizer() on 
non-pointer types. And I can't use any wrappers or pointers to []byte in 
lieu of []byte for my use case.

I figure there is a way to use:

hdr := (*reflect.SliceHeader)(unsafe.Pointer(&b.Payload))

to set a finalizer on the underlying arrray.

But I'm not sure exactly how to convert the hdr.Data into the specific 
array type pointer to use in SetFinalizer().  It may not be possible.

To save some time on a few questions:  I'm aware of the flaws of 
SetFinalizer(), just looking to see if this can actually be done.

Thanks for any help.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/51f0f8db-4f08-4386-87be-48d884a0edb5%40googlegroups.com.

Reply via email to