mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
once memory allocation for batches
parent
caa3b4c6b1
commit
a87dff31b0
@ -179,7 +179,7 @@ Useful if you want to do batch processing on large slices.
|
||||
```go
|
||||
actions := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
||||
batchSize := 3
|
||||
var batches [][]int
|
||||
batches := make([][]int, 0, (len(actions) + batchSize - 1) / batchSize)
|
||||
|
||||
for batchSize < len(actions) {
|
||||
actions, batches = actions[batchSize:], append(batches, actions[0:batchSize:batchSize])
|
||||
|
Loading…
x
Reference in New Issue
Block a user