Exemplo n.º 1
0
        /// <summary>
        /// Returns the number of free bytes in the given arena.
        /// </summary>
        /// <param name="inArena"></param>
        /// <returns></returns>
        static public int ArenaFreeBytes(ArenaHandle inArena)
        {
            ArenaHeader *header = (ArenaHeader *)inArena.HeaderStart;

            if (header != null)
            {
                return((int)header->SizeRemaining);
            }
            return(0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resets the given allocation arena.
        /// </summary>
        static public void ResetArena(ArenaHandle inArena)
        {
            ArenaHeader *header = (ArenaHeader *)inArena.HeaderStart;

            if (header != null)
            {
                header->SizeRemaining = header->Size;
                header->CurrentPtr    = header->StartPtr;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns the size of the given arena.
        /// </summary>
        static public int ArenaSize(ArenaHandle inArena)
        {
            ArenaHeader *header = (ArenaHeader *)inArena.HeaderStart;

            if (header != null)
            {
                return((int)header->Size);
            }
            return(0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Attempts to free the given allocation arena.
        /// </summary>
        static public bool TryFreeArena(ref ArenaHandle ioArena)
        {
            if (ioArena.HeaderStart != null)
            {
                Free(ioArena.HeaderStart);
                ioArena.HeaderStart = null;
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Allocates from the given arena.
        /// </summary>
        static public void *Alloc(ArenaHandle inArena, int inLength)
        {
            ArenaHeader *header = (ArenaHeader *)inArena.HeaderStart;

            if (header == null)
            {
                return(null);
            }

            if (header->SizeRemaining < inLength)
            {
                Log.Warn("[Unsafe] Unable to allocate region of size {0} in arena {1} (size remaining {2})", inLength, header->Name, header->SizeRemaining);
                return(null);
            }

            void *addr = header->CurrentPtr;

            header->CurrentPtr    += inLength;
            header->SizeRemaining -= (uint)inLength;
            return(addr);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Allocates from the given arena with the given alignment.
        /// </summary>
        static public void *AllocAligned(ArenaHandle inArena, int inLength, uint inAlignment)
        {
            ArenaHeader *header = (ArenaHeader *)inArena.HeaderStart;

            if (header == null)
            {
                return(null);
            }

            byte *aligned = (byte *)AlignUpN((ulong)header->CurrentPtr, inAlignment);
            uint  padding = (uint)(aligned - header->CurrentPtr);

            if (header->SizeRemaining < padding + inLength)
            {
                Log.Warn("[Unsafe] Unable to allocate region of size {0} and alignment {1} in arena {2} (size remaining {3})", inLength, inAlignment, header->Name, header->SizeRemaining);
                return(null);
            }

            header->CurrentPtr    += inLength + padding;
            header->SizeRemaining -= (uint)inLength + padding;
            return(aligned);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Frees the given allocation arena.
 /// </summary>
 static public void FreeArena(ArenaHandle inArena)
 {
     Free(inArena.HeaderStart);
 }
Exemplo n.º 8
0
 static public void *AllocArray <T>(ArenaHandle inArena, int inLength)
     where T : struct
 {
     return((void *)AllocAligned(inArena, inLength * SizeOf <T>(), AlignOf <T>()));
 }
Exemplo n.º 9
0
 static public T *AllocArray <T>(ArenaHandle inArena, int inLength)
     where T : unmanaged
 {
     return((T *)AllocAligned(inArena, inLength * sizeof(T), AlignOf <T>()));
 }