处理期望内存大小以字节为单位的CGo函数的规范方法是什么?

I'm playing around with OpenGL and Go. It's mostly pretty intuitive, but there is a few awkward interface problems. The second argument of glBufferData should be the size of the buffer in memory.

C.glBufferData(C.GLenum(target), C.GLsizeiptr(size), ptr(data), C.GLenum(usage))

In the case that the buffer contains 32 bit floats each element will take of 4 bytes, so for the second argument I can do something like:

sizeofFloat := 4
size := sizeofFloat * len(buffer)
C.glBufferData(C.GLenum(target), C.GLsizeiptr(size), ptr(data), C.GLenum(usage))

Is there a better way to get the size of a type in memory other than just hard coding it?

You can use unsafe.Sizeof for that:

This is the easiest since you're already using "unsafe" logic anyway. Otherwise, you might use reflect.Type's Size method for that, to avoid importing unsafe: