Skip to content

Instantly share code, notes, and snippets.

View LarryLuTW's full-sized avatar
🏠
Working from home

Larry Lu LarryLuTW

🏠
Working from home
View GitHub Profile
type Student struct {
name string
address string
grade int32
phone [10]byte
id int8
classID int8
}
type Student struct {
id int8
name string
classID int8
phone [10]byte
address string
grade int32
}
type Student struct {
id int8 // 1 byte
name string // 16 bytes
classID int8 // 1 byte
phone [10]byte // 10 bytes
address string // 16 bytes
grade int32 // 4 bytes
}
struct T2 {
f1 i8
f3 i32
f2 i64
}
struct T1 {
f1 i8
_ [7]byte // 7 bytes padding
f2 i64
f3 i32
_ [4]byte // 4 bytes padding
}
@LarryLuTW
LarryLuTW / T1.go
Last active November 24, 2020 12:19
type T1 struct {
f1 int8 // 1 byte
f2 int64 // 8 bytes
f3 int32 // 4 bytes
}
func main() {
t1 := T1{}
fmt.Println(unsafe.Sizeof(t1)) // 24 bytes
}
@LarryLuTW
LarryLuTW / T2.go
Last active November 24, 2020 12:19
type T2 struct {
f1 int8 // 1 byte
f3 int32 // 4 bytes
f2 int64 // 8 bytes
}
func main() {
t2 := T2{}
fmt.Println(unsafe.Sizeof(t2)) // 16 bytes
}
function sum_to_x(x) {
let sum = 0
for(let i=0; i <= x; i++) {
sum += i
}
return sum
}
function loop_print2() {
for(let x = 0; x * x < 10000; x++) {
print(x)
}
}
function loop_print() {
for(let i = 0; i < 100; i++){
print(i * 500)
}
}