Skip to content

Commit

Permalink
improve: optimal way to use memory
Browse files Browse the repository at this point in the history
  • Loading branch information
zikwall committed Jun 10, 2022
1 parent 42846ba commit 2f1874b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/buffer/memory/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ func (i *memory) Write(row buffer.RowSlice) {
}

func (i *memory) Read() []buffer.RowSlice {
return i.buffer
snapshot := make([]buffer.RowSlice, len(i.buffer))
copy(snapshot, i.buffer)
return snapshot
}

func (i *memory) Len() int {
return len(i.buffer)
}

func (i *memory) Flush() {
i.buffer = make([]buffer.RowSlice, 0, i.size)
i.buffer = i.buffer[:0]
}

0 comments on commit 2f1874b

Please sign in to comment.