import type { IRelease , Type , TypedArray , TypedArrayTypeMap , } from "@thi.ng/api" ; import type { Pow2 } from "@thi.ng/binary" ; export interface MemPoolOpts { /**
     * Backing ArrayBuffer (or SharedArrayBuffer). If not given, a new
     * one will be created with given `size`.
     */ buf : ArrayBufferLike ; defaultValue size : number ; defaultValue start : number ; /**
     * Byte address (+1) of the end of the memory region managed by the
     *  MemPool .
     *
     *  defaultValue end : number ; defaultValue align : Pow2 ; defaultValue compact : boolean ; defaultValue split : boolean ; defaultValue minSplit : number ; /**
     * Only needed when sharing the underlying ArrayBuffer. If true, the
     *  MemPool constructor will NOT initialize its internal state and
     * assume the underlying ArrayBuffer has already been initialized by
     * another  MemPool instance. If this option is used, `buf` MUST be
     * given.
     *
     *  defaultValue skipInitialization : boolean ; } export interface MemPoolStats { /**
     * Free block stats.
     */ free : { count : number ; size : number ; } ; /**
     * Used block stats.
     */ used : { count : number ; size : number ; } ; /**
     * Current top address.
     */ top : number ; /**
     * Bytes available
     */ available : number ; /**
     * Total pool size.
     */ total : number ; } export interface IMemPoolArray extends IRelease { /**
     * Takes a  {@link @thi.ng/api#Type} enum and element count `num` (in
     * units of given type). Similar to  IMemPool . malloc and if
     * successful returns typed array of given `type`.
     * Returns undefined if allocation failed.
     *
     *  param type param num mallocAs < T extends Type > ( type , num ) : TypedArrayTypeMap [ T ] | undefined ; /**
     * Similar to  IMemPoolArray . mallocAs , but if allocation was
     * successful also clears the allocated block w/ `fill` value (default: 0).
     *
     *  param type param num param fill callocAs < T extends Type > ( type , num , fill ? ) : TypedArrayTypeMap [ T ] | undefined ; /**
     * Similar to  IMemPool . realloc , but takes a typed array (one
     * previously allocated with  IMemPoolArray . mallocAs or
     *  IMemPoolArray . callocAs ) and if successul returns new typed array
     * of same type. Implementation is free to return `arr` if new size is same
     * as original. Returns undefined on failure.
     *
     *  param arr param num reallocArray < T extends TypedArray > ( arr , num ) : T | undefined ; param arr free ( arr ) : boolean ; /**
     * Frees all previously allocated blocks and resests allocator state.
     */ freeAll ( ) : void ; } export interface IMemPool extends IMemPoolArray { param size malloc ( size ) : number ; /**
     * Similar to  IMemPool . malloc , but if allocation was successful also
     * clears the allocated block w/ `fill` value (default: 0).
     *
     *  param size param fill calloc ( size , fill ? ) : number ; param ptr param size realloc ( ptr , size ) : number ; /**
     * Takes a memory block address and attempts to return the block to
     * the pool. Depending on `compact` config option, this operation
     * might cause compaction of consecutive free memory blocks to help
     * counter fragmentation. Returns true if block has been freed.
     *
     * It's the user's responsibility to ensure that freed blocks are
     * not used any further after calling  IMemPool . free .
     * Undefined behavior, or worse, pool corruption might ensue!
     *
     *  param ptr free ( ptr ) : boolean ; /**
     * Returns an information object of the pool's state.
     */ stats ( ) : Readonly < MemPoolStats > ; }