Interesting. I would think that with a dataset that large, the
bottleneck would be the speed of your rotating media. What speeds are
you seeing?
yours,
Bobby
binary/encoding could definitely be more efficient. i think
i did some work on making reading and writing slices a bit
better a while back but i never submitted the code.
BTW if you must use unsafe, here's a perhaps
more efficient way of doing it, which avoids the
allocation, although it's a little more verbose.
i *think* it's GC-safe.
func FastRead16(in io.Reader, buf []uint16) (int, error) {
var bytes []byte
h := (*reflect.SliceHeader)(unsafe.Pointer(&bytes))
h.Len = len(buf) * 2
h.Cap = cap(buf) * 2
if len(buf) > 0 {
h.Data = uintptr(unsafe.Pointer(&buf[0]))
}
n, err := io.ReadFull(in, bytes)
return n / 2, err
}
Great, I saw some similar code in the RAW ('Random Access Woes')
package and now it makes sense.
Naturally, I would prefer not to use unsafe for something as routine
as reading binary data. But the speed benefits are too good to be
ignored (more than an order of magnitude).
steve d.