Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS (WIN) Common - Mem MGR.c
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
    following conditions are met:
    Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
    Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
    provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Internal Platform Functions                                                                                                                                           */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

TgEXTN P_TgUINT08                           tgMM_PM_Init_Scratch( C_TgSIZE );
TgEXTN TgVOID                               tgMM_PM_Free_Scratch( PC_TgUINT08 );
TgEXTN TgUINT32                             tgMM_PM_Page_Size( TgVOID );
TgEXTN P_TgVOID                             tgMM_PM_Virtual_Reserve( C_TgSIZE, C_TgBOOL );
TgEXTN P_TgVOID                             tgMM_PM_Virtual_Commit( PC_TgVOID, C_TgSIZE );
TgEXTN TgVOID                               tgMM_PM_Virtual_Free( PC_TgVOID );




/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Internal Functions                                                                                                                                                    */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* ---- tgMM_PM_Init_Scratch -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
P_TgUINT08 tgMM_PM_Init_Scratch( C_TgSIZE uiSize )
{
    return ((P_TgUINT08)_aligned_malloc( uiSize, 16 ));
}


/* ---- tgMM_PM_Free_Scratch -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgMM_PM_Free_Scratch( PC_TgUINT08 pScratchMemory )
{
    _aligned_free( pScratchMemory );
}


/* ---- tgMM_PM_Page_Size ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgUINT32 tgMM_PM_Page_Size( TgVOID )
{
    return (tgSI_SYSTEM_Page_Size());
}


/* ---- tgMM_PM_Virtual_Reserve ----------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
P_TgVOID tgMM_PM_Virtual_Reserve( C_TgSIZE iSize, C_TgBOOL bTemp )
{
#if defined(TgCOMPILE_PLATFORM_UWP)
    return (g_pfnVirtualAllocFromApp( nullptr, iSize, 0x2000 | (bTemp ? 0x100000 : 0), 0x04 ));
#else
    return (g_pfnVirtualAlloc( nullptr, iSize, 0x2000 | (bTemp ? 0x100000 : 0), 0x04 ));
#endif
}


/* ---- tgMM_PM_Virtual_Commit ------------------------------------------------------------------------------------------------------------------------------------------ */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
P_TgVOID tgMM_PM_Virtual_Commit( PC_TgVOID pMem, C_TgSIZE iSize )
{
#if defined(TgCOMPILE_PLATFORM_UWP)
    PC_TgVOID pCheck = g_pfnVirtualAllocFromApp( pMem, iSize, 0x1000 | (nullptr == pMem ? 0x2000 : 0), 0x04 );
#else
    PC_TgVOID pCheck = g_pfnVirtualAlloc( pMem, iSize, 0x1000 | (nullptr == pMem ? 0x2000 : 0), 0x04 );
#endif
    TgCRITICAL( (0 == pMem) || (0 == pCheck) || (pCheck == (P_TgVOID)((TgUINTPTR)pMem & (~(TgUINTPTR)(tgMM_Page_Size() - 1)))) );
    return (pCheck);
}


/* ---- tgMM_PM_Virtual_Free -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgVOID tgMM_PM_Virtual_Free( PC_TgVOID pMem )
{
    TgVERIFY( 0 != g_pfnVirtualFree( pMem, 0, 0x8000 ) );
}