December 12, 2013

Go: How slices grow

Posted in Software at 05:49 by graham

In Go (golang) what happens to memory when you append to a slice?

If there’s enough space in the slice’s backing array, the element just gets added. If there’s not enough space, a new array is allocated, all the items are copied over, and the new item is added at the end. The interesting part is allocating that new array. And here’s the answer:

Go slices grow by doubling until size 1024, after which they grow by 25% each time

This is an implementation detail and may change. The above is correct for Go 1.1 and 1.2.

Try it out:

package main

import "fmt"

func main() {
    var x []int  // Same as x := make([]int, 0)
    for i := 0; i < 100; i++ {
        fmt.Printf("%d: %p cap %d\n", i, x, cap(x))
        x = append(x, i)
    }
}

Read the rest of this entry »

December 8, 2013

My setup: Hardware

Posted in Behaviour at 00:46 by graham

Here’s my current setup, and the hardware I got, in case you were curious. And because I know I’ll be curious in a few years.

  • Aeron chair: Are the any other type of office chairs? I don’t think so. At least there shouldn’t be. You can usually get one cheap from a failing startup in your area.

  • INGO Ikea sitting desk: A plenty big enough desk, of solid wood, and cheap. It’s marketed as a kitchen table. I’ve owned three of these so far.

  • BJORKUDDEN Ikea standing desk: A little bit too short for me, so I have some phone books on top. Getting a standing desk the right height is tricky, because your legs don’t adjust, unlike a chair, so it has to be perfect. This as close as I could find without spending a fortune. I stand about 50% of the time when I’m programming, but not 50% of the day. Some days I mostly stand, others I mostly sit. Standing after lunch helps a lot in overcoming the post-lunch coma. The Bjorkudden is marketed as a bar table.

Hardware

Read the rest of this entry »

December 7, 2013

Kinesis Advantage after four months

Posted in Software at 23:58 by graham

I have been using a Kinesis Advantage keyboard for the past four months, since August. I love it. Here’s my trip report.

Kinesis Advantage

Before this keyboard I had been using Microsoft Natural keyboards for many many years.

Let’s cut straight to the chase: The first three days were very hard. It’s the same feeling as when I switched to vim. You tell your fingers to do something and they don’t do it. It’s especially hard when you do lots of text chat. My typing rate went way down, so I couldn’t ‘talk’ as fast.

Read the rest of this entry »