ortuman / nuke

⚡ A memory arena implementation for Go.
Apache License 2.0
500 stars 13 forks source link

slab: alloc looks fishy #1

Closed sbinet closed 8 months ago

sbinet commented 8 months ago

it seems to me this is fishy:

https://github.com/ortuman/nuke/blob/e765a1e99d3cc1afee1dd7c21110c0e77bfd3dee/slab_arena.go#L87..L88

func (a *slabArena) Alloc(size int) unsafe.Pointer {
    for i := 0; i < len(a.slabs); i++ {
        ptr, ok := a.slabs[0].alloc(size)

shouldn't it read:

func (a *slabArena) Alloc(size int) unsafe.Pointer {
    for i := 0; i < len(a.slabs); i++ {
        ptr, ok := a.slabs[i].alloc(size) // !!!

instead ?

ie:

func (a *slabArena) Alloc(size int) unsafe.Pointer {
    for i := 0; i < len(a.slabs); i++ {
-       ptr, ok := a.slabs[0].alloc(size)
+       ptr, ok := a.slabs[i].alloc(size)
ortuman commented 8 months ago

good catch and thanks for reporting! that's a bug indeed.

fixed it and made a new release available 👉 https://github.com/ortuman/nuke/releases/tag/v1.0.1