/vkmm_java

Primary LanguageJavaThe UnlicenseUnlicense

Vulkan Memory Managers (Java)

Implementation of multiple types of Memory Allocators and a generic MemoryManager.

Buddy Block Allocator

Implements Buddy Memory Allocation. Works by recursively subdividing into two blocks of at least MIN_SUBDIV_SIZE. Each block has a buddy block. When A block and its buddy are freed, the parent is also considered freed.

Linear Memory Allocator

Allocates memory sequentially. Allocations from this memory allocator cannot be freed. Instead, the entire Memory Allocator can be reset, which effectively frees all allocations. Clearing the Linear Memory Allocator does not notify allocations that they are now undefined.

Slab Memory Allocator

Pre-subdivides memory allocations into n-bins. Allocation works by selecting from the best-fit bin and marking that memory as used. This allocator is ideal for a small memory pool.

Stack Memory Allocator

Allocates memory by growing downwards. Supports push and pop. Push remembers the current frame index, while pop resets the frame to the previous frame index. A pop effectively frees all memory allocated within a stack frame.

Unique Memory Allocator

Allocates memory as unique calls to VkAllocateMemory. This is not ideal, since Vulkan limits the number of active Memory Allocations to as low as ~1000 (dependent on hardware). This memory allocator is best used for small demos, large memory allocations, or allocations that persist through the entire lifespan of the application.

MemoryManager

Implements multiple Memory Allocators and selects from them depending on heuristics configured at startup.

Default settings result in:

  • Use UniqueMemoryAllocator when allocation is above 128MB
  • Use BuddyBlockAllocator(s) when between 32KB and 128MB
  • Use SlabAllocator(s) when less than or equal to 32KB.

Default SlabAllocator Slab Sizes:

  • 256x 4KB allocations
  • 128x 8KB allocations
  • 64x 16KB allocations
  • 32x 32KB allocations

Additional BuddyBlockAllocators and SlabAllocators will be constructed if all available allocators are full (for the given range).