> > The garbage collector does not care about the values of items of a []T > when T is not a pointer type nor a type containing transitively any > pointers. > Just to make sure I understand you correctly. Are you saying I could hold an unsafe.Pointer to an array of uint64 and the GC will still not care about what is inside that array? Because that is my concern here.
> However, do not play games with fake lengths and/or capacities of a slice, > namely setting them to a larger than actual value. Go supports interior > pointers pointing inside allocated memory blocks and the mechanism > implementing this feature could be easily tripped by such invalid values in > the general case, event though possibly not for a particular Go compiler. > Thanks for the warning. This disqualifies option 1. > An easy way how to avoid any nasty interactions with the runtime is to > manually allocate/deallocate memory holding the bit array. See for example: > http://github.com/cznic/memory. I'd use the uintptr returning variants > making GC absolutely uninterested in the value. Any for the pointer > arithmetic you have to perform the calculations on uintptrs anyway. > Well, I would have to track the memory myself then (BitSlice should support slicing similar to normal slices) and can't work with memory supplied by the user or give the user references to it (such as using a user provided []uint64 for constructing the BitSlice or returning a []uint64 to the user). I'm afraid this is not viable. I didn't state any of these requirements initially, so you couldn't have known. However, do you already have a positive proof that the bound checks are > substantially expensive in your use case? > Yes absolutely, the performance difference is significant. But this isn't about removing bounds checks. We can already skip those by forcing early bounds checks for the last word, so the compiler can remove the rest. The idea here is to reduce the size of the BitSlice struct by a word or two. -- 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.