Skip to content

Commit 91c8cc8

Browse files
committed
gofmt cache-lines example
1 parent fd3e450 commit 91c8cc8

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

examples/cache-lines.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ package main
22

33
// Large struct that spans multiple cache lines (64 bytes each)
44
type LargeStruct struct {
5-
A uint64 // 0-7 (cache line 0)
6-
B uint64 // 8-15 (cache line 0)
7-
C uint64 // 16-23 (cache line 0)
8-
D uint64 // 24-31 (cache line 0)
9-
E uint64 // 32-39 (cache line 0)
10-
F uint64 // 40-47 (cache line 0)
11-
G uint64 // 48-55 (cache line 0)
12-
H uint64 // 56-63 (cache line 0) - exactly fills line 0
13-
I uint64 // 64-71 (cache line 1)
14-
J uint64 // 72-79 (cache line 1)
5+
A uint64 // 0-7 (cache line 0)
6+
B uint64 // 8-15 (cache line 0)
7+
C uint64 // 16-23 (cache line 0)
8+
D uint64 // 24-31 (cache line 0)
9+
E uint64 // 32-39 (cache line 0)
10+
F uint64 // 40-47 (cache line 0)
11+
G uint64 // 48-55 (cache line 0)
12+
H uint64 // 56-63 (cache line 0) - exactly fills line 0
13+
I uint64 // 64-71 (cache line 1)
14+
J uint64 // 72-79 (cache line 1)
1515
}
1616

1717
// Struct with a field that crosses cache line boundary
1818
type CacheLineCrosser struct {
19-
Padding [60]byte // 0-59 (cache line 0)
20-
Big [16]byte // 60-75 - CROSSES cache line 0→1!
21-
After uint64 // 80-87 (cache line 1)
19+
Padding [60]byte // 0-59 (cache line 0)
20+
Big [16]byte // 60-75 - CROSSES cache line 0→1!
21+
After uint64 // 80-87 (cache line 1)
2222
}
2323

2424
// False sharing example - commonly accessed together but on different lines
@@ -38,12 +38,12 @@ type CacheAligned struct {
3838

3939
// Typical struct that may cross cache lines unintentionally
4040
type HTTPRequest struct {
41-
Method string // 0-15 (16 bytes)
42-
URL string // 16-31 (16 bytes)
43-
Headers []byte // 32-55 (24 bytes slice header)
44-
Body []byte // 56-79 - CROSSES cache line!
45-
ContentLen int64 // 80-87
46-
StatusCode int32 // 88-91
47-
IsSecure bool // 92
48-
KeepAlive bool // 93
41+
Method string // 0-15 (16 bytes)
42+
URL string // 16-31 (16 bytes)
43+
Headers []byte // 32-55 (24 bytes slice header)
44+
Body []byte // 56-79 - CROSSES cache line!
45+
ContentLen int64 // 80-87
46+
StatusCode int32 // 88-91
47+
IsSecure bool // 92
48+
KeepAlive bool // 93
4949
}

0 commit comments

Comments
 (0)