"""
Auto-generated Python stub file from memhub.py
Module: memhub
"""


import t, c
from stdint import *
import string
import atom
import viperio
import stdio

MEMHUB_ALIGN: t.CDefine = 8
MEMSLAB_MIN_BLOCK: t.CDefine = 16
MEMSLAB_BITMAP_BYTES: t.CDefine = 256
MEMBUDDY_MIN_BLOCK: t.CDefine = 32
MEMBUDDY_MAX_ORDERS: t.CDefine = 32
MEMBUDDY_HEADER_SIZE: t.CDefine = 8

def _align_up(val: t.CSizeT, align: t.CSizeT) -> t.CSizeT: pass

def _largest_pow2_le(val: t.CSizeT) -> t.CSizeT: pass

def _block_size_at_order(order: t.CInt) -> t.CSizeT: pass


@t.CVTable
class MemManager:
    __provides__: list[str] = ['__memmgr__']
    base: t.CVoid | t.CPtr
    size: t.CSizeT
    def __init__(self: MemManager, base: t.CVoid | t.CPtr, size: t.CSizeT) -> t.CInt: pass
    def alloc(self: MemManager, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
    def free(self: MemManager, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
    def reset(self: MemManager) -> t.CInt: pass
    def calloc(self: MemManager, count: t.CSizeT, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
    def realloc(self: MemManager, ptr: t.CVoid | t.CPtr, new_size: t.CSizeT) -> t.CVoid | t.CPtr: pass
    def __enter__(self: MemManager) -> 'MemManager' | t.CPtr: pass
    def __exit__(self: MemManager) -> t.CInt: pass
    def alloc_buf(self: MemManager, capacity: t.CSizeT) -> viperio.Buf | t.CPtr: pass
class MemPool(MemManager):
    offset: t.CSizeT
    high_water: t.CSizeT
    def __init__(self: MemPool, base: t.CVoid | t.CPtr, size: t.CSizeT) -> t.CInt: pass
    def alloc(self: MemPool, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
    def free(self: MemPool, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
    def reset(self: MemPool) -> t.CInt: pass
class MemSlab(MemManager):
    block_size: t.CSizeT
    block_count: t.CSizeT
    used_count: t.CSizeT
    free_list: t.CVoid | t.CPtr
    alloc_map: t.CUInt8T | t.CPtr
    alloc_map_size: t.CSizeT
    usable: t.CVoid | t.CPtr
    usable_size: t.CSizeT
    def __init__(self: MemSlab, base: t.CVoid | t.CPtr, size: t.CSizeT, block_size: t.CSizeT) -> t.CInt: pass
    def alloc(self: MemSlab, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
    def free(self: MemSlab, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
    def reset(self: MemSlab) -> t.CInt: pass
class MemBuddy(MemManager):
    __provides__: list[str] = ['__mbuddy__', '__memmgr__']
    max_order: t.CInt
    free_lists: t.CUInt64T | t.CPtr
    lock_val: t.CVolatile | t.CInt
    usable: t.CVoid | t.CPtr
    usable_size: t.CSizeT
    def __init__(self: MemBuddy, base: t.CVoid | t.CPtr, size: t.CSizeT) -> t.CInt: pass
    def _fl_push(self: MemBuddy, order: t.CInt, block: t.CVoid | t.CPtr) -> t.CInt: pass
    def _fl_pop(self: MemBuddy, order: t.CInt) -> t.CVoid | t.CPtr: pass
    def _fl_find_and_remove(self: MemBuddy, order: t.CInt, target: t.CVoid | t.CPtr) -> t.CInt: pass
    def _buddy_of(self: MemBuddy, block: t.CVoid | t.CPtr, order: t.CInt) -> t.CVoid | t.CPtr: pass
    def _order_for_size(self: MemBuddy, size: t.CSizeT) -> t.CInt: pass
    def _split_to_order(self: MemBuddy, to_order: t.CInt) -> t.CVoid | t.CPtr: pass
    def _coalesce(self: MemBuddy, block: t.CVoid | t.CPtr, order: t.CInt) -> t.CInt: pass
    def _is_valid_ptr(self: MemBuddy, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
    def _lock(self: MemBuddy) -> t.CInt: pass
    def _unlock(self: MemBuddy) -> t.CInt: pass
    def alloc(self: MemBuddy, size: t.CSizeT) -> t.CVoid | t.CPtr: pass
    def free(self: MemBuddy, ptr: t.CVoid | t.CPtr) -> t.CInt: pass
    def reset(self: MemBuddy) -> t.CInt: pass
    def realloc(self: MemBuddy, ptr: t.CVoid | t.CPtr, new_size: t.CSizeT) -> t.CVoid | t.CPtr: pass
    @property
    def mem_size(self: MemBuddy) -> t.CSizeT: pass
    def stats(self: MemBuddy) -> t.CSizeT: pass
    def free_count(self: MemBuddy) -> t.CSizeT: pass
    def self_check(self: MemBuddy) -> t.CInt: pass