优化计数器内存使用

This commit is contained in:
刘祥超
2023-10-04 16:53:39 +08:00
parent 263acb775b
commit 0736b20d33
4 changed files with 39 additions and 9 deletions

View File

@@ -24,9 +24,9 @@ func NewItem(lifeSeconds int) *Item {
spanSeconds = 1
}
var countSpans = lifeSeconds/spanSeconds + 1 /** prevent index out of bounds **/
var spans = []*Span{}
var spans = make([]*Span, countSpans)
for i := 0; i < countSpans; i++ {
spans = append(spans, NewSpan())
spans[i] = NewSpan()
}
return &Item{