From a87dff31b0d8ae8f26902b0d2dbe7e4e77c7e6e3 Mon Sep 17 00:00:00 2001 From: Bator Tsyrendylykov Date: Wed, 15 Jan 2020 11:58:54 +0300 Subject: [PATCH] once memory allocation for batches --- SliceTricks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SliceTricks.md b/SliceTricks.md index 653157ad..18a57fe9 100644 --- a/SliceTricks.md +++ b/SliceTricks.md @@ -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])