Skip to content

proposal: arena: add MakeMap #56230

@dsnet

Description

@dsnet

I noticed that making of Go maps was missing from the original proposal in #51317. The proposal says:

Another open issue is whether arenas can be used for allocating the elements of a map. This is
possible, but it is not clear what a good API would be. Also, there might be unusual cases if the arena used for the main map object is different from the arena used to allocate new elements of the map.

Perhaps I'm missing something, but couldn't we construct a Go map with an arena registered with it such that all allocations needed by the map are performed out of the arena? Thus, we're not directly allocating the elements of a map, but rather the entire map and (indirectly any map elements henceforth).

Something like:

// MakeMap creates a new map[K]V with the provided capacity.
// The map[K]V must not be used after the arena is freed.
// Accessing the underlying storage of the map after free may result in a fault,
// but this fault is also not guaranteed.
func MakeMap[K comparable, V any](a *Arena, cap int) map[K]V { ... }

\cc @danscales

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions