Announcing Gommap

169 views
Skip to first unread message

Gustavo Niemeyer

unread,
Nov 28, 2010, 1:40:43 PM11/28/10
to golang-nuts
Greetings,

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

nsf

unread,
Nov 28, 2010, 2:49:06 PM11/28/10
to golan...@googlegroups.com

A very interesting blog post, thanks. Useful package too.

jimt

unread,
Nov 28, 2010, 7:35:59 PM11/28/10
to golang-nuts
Nice work! This may just solve my issues with the kernel module
wrapper I was writing for V4L (Video For Linux). Once I get my webcam
back, I can test it. I'll let you know how it works out.

Eleanor McHugh

unread,
Nov 29, 2010, 12:56:41 PM11/29/10
to golang-nuts
On 28 Nov 2010, at 18:40, Gustavo Niemeyer wrote:
> Greetings,
>
> 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

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


Gustavo Niemeyer

unread,
Nov 30, 2010, 11:25:10 AM11/30/10
to Eleanor McHugh, golang-nuts
> Very nice :)

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.

Russ Cox

unread,
Dec 2, 2010, 10:25:39 AM12/2/10
to Gustavo Niemeyer, Eleanor McHugh, golang-nuts
> 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.

Why would you need to say []uint8(mmap)?

Russ

Gustavo Niemeyer

unread,
Dec 2, 2010, 10:46:15 AM12/2/10
to r...@golang.org, Eleanor McHugh, golang-nuts
> Why would you need to say []uint8(mmap)?

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.

Gustavo Niemeyer

unread,
Dec 2, 2010, 4:49:32 PM12/2/10
to r...@golang.org, Eleanor McHugh, golang-nuts
> 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.

Reply all
Reply to author
Forward
0 new messages