The blog post has some interesting details about how it was done and why:
Removing seatbelts with the Go language for mmap support:
http://j.mp/gommap
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/blog
http://niemeyer.net/twitter
A very interesting blog post, thanks. Useful package too.
Very nice :)
I can't help but wonder though if there isn't a way of replacing the MMap struct with just a []uint8 derived type... if I can make some time I'll have a hack and see how that works.
Ellie
Eleanor McHugh
Games With Brains
twitter: @feyeleanor
----
raise ArgumentError unless @reality.responds_to? :reason
Thanks! (to everyone)
> I can't help but wonder though if there isn't a way of replacing the MMap struct with just a []uint8 derived type... if I can make some time I'll have a hack and see how that works.
Yes, I pondered about this alternative too, and technically it would
certainly work that way, but doing so would also force the casting
back to []uint8, and would force keeping two different variables
around: mmap for the methods, and []uint8(mmap) for usage. mmap +
mmap.Data gives exactly that, in a comfortable way, so I opted to go
down that route.
Why would you need to say []uint8(mmap)?
Russ
I think I misunderstood the situations in which automatic casting happens.
I assumed that this would fail, for instance, but it doesn't:
type MMap []uint8
func main() {
mmap := MMap([]uint8("testing"))
println(bytes.Index(mmap, []byte("st"))) // <=
}
I recall even testing it, but obviously I must have made a mistake.
I will reimplement gommap with this approach to see how it feels.
Ok, it was quite simple to convert (took less than 10 minutes).
Indeed in a few places additional type casting is needed (e.g.
string(mmap) doesn't work, for instance), and the type can now be
built manually by doing MMap(array), which is both an advantage or a
bug, depending on what kind of trickery someone is doing.
(MMap(array).Protect(PROT_READ) for added fun).
The new version is available through goinstall.. let's see how people
feel about this.