InventoryPool

data object InventoryPool

A soft-reference based pool of Inventory objects, with the primary intent being to avoid re-creating lists of objs which end up wasting as much as 137kb of memory for a single inventory that's up to 5713 objs in capacity. While it is unlikely that any inventory would get near that, servers do commonly expand inventory capacities to numbers like 2,000 or 2,500, which would still consume up 48-60kb of memory as a result in any traditional manner.

Breakdown of the above statements: Assuming an implementation where List is provided to the respective packets, where Obj is a class of three properties:

Slot: Int (necessary for partial inv updates)
Id: Int
Count: Int

The resulting memory requirement would be (12 + (3 * 4)) bytes per obj. While this does coincide with the memory alignment, it still ends up consuming 24 bytes per obj, all of which would be discarded shortly after. Given the assumption that 1,000 players log in at once, and they all have a bank of 1000 objs - which is a fairly conservative estimate -, the resulting waste of memory is 24 megabytes alone. All of this can be avoided through the use of an object pool, as done below.

Properties

Link copied to clipboard
val pool: ObjectPool<Inventory>