Skip to content

Conversation

@kostaspap
Copy link

The way the Arena is meant to be used as highlighted here

 1) Construct Values via the Arena and Value.Set* calls.
 2) Marshal the constructed Values with Value.MarshalTo call.
 3) Reset all the constructed Values at once by Arena.Reset call.
 4) Go to 1 and re-use the Arena.

When using the ArenaPool, someone would have then to manually reset the Arena before returning it to the Pool

var pool fastjson.ArenaPool
....

func foo() {
....
  arena := pool.Get()
  defer func() {
    arena.Reset()
    pool.Put(arena)
  }
...
}

Which results in many repetitive code or worse, using the API wrong (e.g. putting the Arena in the ArenaPool before resetting it)

Looking at the description of the ArenaPool#Put method as described here
it makes me think that the intention was that ArenaPool#Put would reset the pool

@kostaspap kostaspap changed the title Resetting the Arena before putting it to the ArenaPool Putting the Arena in the ArenaPool resets it May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant