Memory object allocation

There are three classifications of memory objects:

  • Tiny: An object that is less than 16 bytes in size
  • Small: An object that is greater than 16 bytes and less than or equal to 32 kB
  • Large: An object that is larger than 32 kB in size

A tiny object in memory in Go performs the following process for memory allocation:

  1. If P's mcache has room, use that space.
  2. Take the existing sub object in the mcache and round it to 8, 4, or 2 bytes.
  3. Place the object in memory if it fits in the allocated space.

A small object in memory in Go follows a specific pattern for memory allocation:

  1. The object's size gets rounded up and classified into one of the small size classes that are generated in https://golang.org/src/runtime/mksizeclasses.go ...

Get Hands-On High Performance with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.