Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

DDMemMgr.cpp

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  DDMemMgr.c                                                                          */
00003 /*                                                                                      */
00004 /*  Author: John Pollard                                                                */
00005 /*  Description: Mini D3D memory manager                                                */
00006 /*                                                                                      */
00007 /*  The contents of this file are subject to the Genesis3D Public License               */
00008 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00009 /*  compliance with the License. You may obtain a copy of the License at                */
00010 /*  http://www.genesis3d.com                                                            */
00011 /*                                                                                      */
00012 /*  Software distributed under the License is distributed on an "AS IS"                 */
00013 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00014 /*  the License for the specific language governing rights and limitations              */
00015 /*  under the License.                                                                  */
00016 /*                                                                                      */
00017 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00018 /*  Genesis3D Version 1.1 released November 15, 1999                                    */
00019 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved                            */
00020 /*                                                                                      */
00021 /****************************************************************************************/
00022 #include <Windows.h>
00023 
00024 #include "BaseType.h"
00025 #include "DDMemMgr.h"
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 #define DDMEMMGR_MAX_PARTITIONS                         16
00037 
00038 typedef struct DDMemMgr_Partition
00039 {
00040         geBoolean       Active;
00041         uint32          FreeMem;
00042         uint32          TotalMem;
00043 
00044 } DDMemMgr_Partition;
00045 
00046 typedef struct DDMemMgr
00047 {
00048         uint32                          TotalMem;
00049         uint32                          FreeMem;
00050         DDMemMgr_Partition      Partitions[DDMEMMGR_MAX_PARTITIONS];                    
00051 } DDMemMgr;
00052 
00053 //============================================================================
00054 //      DDMemMgr_Create
00055 //============================================================================
00056 DDMemMgr *DDMemMgr_Create(uint32 Size)
00057 {
00058         DDMemMgr        *MemMgr;
00059 
00060         MemMgr = (DDMemMgr*)malloc(sizeof(DDMemMgr));
00061 
00062         if (!MemMgr)
00063                 return NULL;
00064 
00065         memset(MemMgr, 0, sizeof(DDMemMgr));
00066 
00067         MemMgr->TotalMem = Size;
00068         MemMgr->FreeMem = Size;
00069 
00070         return MemMgr;
00071 }
00072 
00073 //============================================================================
00074 //      DDMemMgr_Destroy
00075 //============================================================================
00076 void DDMemMgr_Destroy(DDMemMgr *MemMgr)
00077 {
00078         free(MemMgr);
00079 }
00080 
00081 //============================================================================
00082 //      DDMemMgr_Reset
00083 //============================================================================
00084 void DDMemMgr_Reset(DDMemMgr *MemMgr)
00085 {
00086         int32           i;
00087 
00088         MemMgr->FreeMem = MemMgr->TotalMem;
00089 
00090         for (i=0; i<DDMEMMGR_MAX_PARTITIONS; i++)
00091                 memset(&MemMgr->Partitions[i], 0, sizeof(DDMemMgr_Partition));
00092 }
00093 
00094 //============================================================================
00095 //      DDMemMgr_GetFreeMem
00096 //============================================================================
00097 uint32 DDMemMgr_GetFreeMem(DDMemMgr *MemMgr)
00098 {
00099         return MemMgr->FreeMem;
00100 }
00101 
00102 //============================================================================
00103 //      DDMemMgr_PartitionCreate
00104 //============================================================================
00105 DDMemMgr_Partition *DDMemMgr_PartitionCreate(DDMemMgr *MemMgr, uint32 Size)
00106 {
00107         int32                                   i;
00108         DDMemMgr_Partition              *pPartition;
00109 
00110         if (Size > MemMgr->FreeMem)
00111                 return NULL;
00112                 
00113         pPartition = MemMgr->Partitions;
00114 
00115         for (i=0; i< DDMEMMGR_MAX_PARTITIONS; i++, pPartition++)
00116         {
00117                 if (!pPartition->Active)
00118                 {
00119                         pPartition->TotalMem = Size;
00120                         pPartition->FreeMem = Size;
00121                         pPartition->Active = GE_TRUE;
00122                         MemMgr->FreeMem -= Size;
00123 
00124                         return pPartition;
00125                 }
00126         }
00127 
00128         return NULL;
00129 }
00130 
00131 //============================================================================
00132 //      DDMemMgr_PartitionDestroy
00133 //============================================================================
00134 void DDMemMgr_PartitionDestroy(DDMemMgr_Partition *Partition)
00135 {
00136         memset(Partition, 0, sizeof(DDMemMgr_Partition));
00137 }
00138 
00139 //============================================================================
00140 //      DDMemMgr_PartitionReset
00141 //============================================================================
00142 void DDMemMgr_PartitionReset(DDMemMgr_Partition *Partition)
00143 {
00144         Partition->FreeMem = Partition->TotalMem;
00145 }
00146 
00147 //============================================================================
00148 //      DDMemMgr_PArtitionGetTotalMem
00149 //============================================================================
00150 uint32 DDMemMgr_PartitionGetTotalMem(DDMemMgr_Partition *Partition)
00151 {
00152         return Partition->TotalMem;
00153 }
00154 
00155 //============================================================================
00156 //      DDMemMgr_PArtitionGetFreeMem
00157 //============================================================================
00158 uint32 DDMemMgr_PartitionGetFreeMem(DDMemMgr_Partition *Partition)
00159 {
00160         return Partition->FreeMem;
00161 }
00162 
00163 //============================================================================
00164 //      DDMemMgr_PartitionAllocMem
00165 //============================================================================
00166 geBoolean DDMemMgr_PartitionAllocMem(DDMemMgr_Partition *Partition, uint32 Size)
00167 {
00168         if (Partition->FreeMem < Size)
00169                 return GE_FALSE;
00170 
00171         Partition->FreeMem -= Size;
00172 
00173         return GE_TRUE;
00174 }

Generated on Tue Sep 30 12:35:36 2003 for GTestAndEngine by doxygen 1.3.2