Note slices do not allocate on every append/reslice... if you preallocate the slice for all elements you can avoid the allocations.
You can take a look at https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html -- vector is quite similar to slice. If you cannot preallocate then you can use deque structure: https://github.com/karalabe/cookiejar/blob/master/collections/deque/deque.go *Replace `interface{}` with whatever type you are using.* On Wednesday, 30 August 2017 12:34:16 UTC+3, BeaT Adrian wrote: > > I want to make some data structures that can handle millions of entries. I > will dome some benchmarks, but in theory slices should be slower (all that > allocating/reallocating arrays behind the scenes). I don't know the size of > the structures and I only need the first/last element. > > On Tuesday, August 29, 2017 at 8:24:58 PM UTC+3, Egon wrote: >> >> Is there a reason you are using `container/list`, in most cases it's the >> wrong solution. Slices in most cases are faster and use less resources and >> easier to work with. >> >> + Egon >> >> On Tuesday, 29 August 2017 01:50:10 UTC+3, BeaT Adrian wrote: >>> >>> Hello, I just started to learn golang and I have a small dillema. >>> >>> My programming is too defensive OR how can I replicate this scenario >>> (for my test coverage sake) >>> >>> list = list.New() >>> element := list.PushBack(item) >>> if element == nil { >>> //don't know how this can happen, just being defensive >>> return false >>> } >>> >>> >>> or >>> element:= list.Back() >>> //can element be nil ? >>> >>> I browsed the list.List code but still haven't found a solution how to >>> replicate this case. >>> >>> Thanks!! >>> >>> >>> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.