Skip to main content
  1. Tutorial/

内存对齐-fieldalignment

33 words·1 min
Golang
Table of Contents

fieldalignment
#

Install

go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest

golangci-lint 会对结构体的内存字节对齐进行检查,会报下面的错误

# fieldalignment -fix grpc.go
/home/workspace/test/grpc.go:6:14: struct with 96 pointer bytes could be 88

go官方提供了fieldalignment 检测和修复工具,可以快速的帮我们解决内存对齐扣字节的问题

fieldalignment -fix ./xxx/xxx

说明:参数 -fix 会自动帮我们做到内存对齐,不需要我们做额外的操作; 参数 ./xxx/xxx 是我们的需要fix 的文件的包路径即pkg的目录

Related

50 Shades of Go
11898 words·56 mins
Golang
50 Shades of Go: Traps, Gotchas, and Common Mistakes for New Golang Devs # Traps, Gotchas, and Common Mistakes # level: beginner In most other languages that use braces you get to choose where you place them.
简单实现QPS计算
280 words·2 mins
Golang
Simple QPS # 实现一个简单的QPS(每秒查询率)测试。
数据结构&控制结构实现原理
564 words·3 mins
Golang
Map 扩容条件与操作原理 # 负载因子 > 6.
Download and install - The Go Programming Language
317 words·2 mins
Kiga-Hub
Casual Essay
Golang
Download and install # Download and install Go quickly with the steps described here.
Centos8: Errors during downloading metadata for repository 'base'
87 words·1 min
Linux
Errors during downloading metadata for repository ‘base‘ # CentOS-8 - Base - mirrors.