static GUI_HMEM FindFreeHandle(void) { int i; for (i=1; i< GUI_MAXBLOCKS; i++) { if (aBlock[i].Size ==0) return i; } GUI_DEBUG_ERROROUT1("Insufficient memory handles configured (GUI_MAXBLOCKS == %d (See GUIConf.h))", GUI_MAXBLOCKS); return GUI_HMEM_NULL; }
/********************************************************************* * * _Alloc */ static GUI_HMEM _Alloc(GUI_ALLOC_DATATYPE size) { GUI_HMEM hMemNew, hMemIns; _CheckInit(); size = _Size2LegalSize(size); /* Check if memory is available at all ...*/ if (size > _GetNumFreeBytes()) { GUI_DEBUG_WARN1("GUI_ALLOC_Alloc: Insufficient memory configured (Trying to alloc % bytes)", size); return 0; } /* Locate free handle */ if ((hMemNew = _FindFreeHandle()) == 0) { return 0; } /* Locate or Create hole of sufficient size */ hMemIns = _FindHole(size); #if GUI_ALLOC_AUTDEFRAG if (hMemIns == -1) { if (_LockCnt == 0) { hMemIns = _CreateHole(size); } } #endif /* Occupy hole */ if (hMemIns==-1) { GUI_DEBUG_ERROROUT1("GUI_ALLOC_Alloc: Could not allocate %d bytes",size); return 0; } { GUI_ALLOC_DATATYPE Off = aBlock[hMemIns].Off + aBlock[hMemIns].Size; int Next = aBlock[hMemIns].Next; aBlock[hMemNew].Size = size; aBlock[hMemNew].Off = Off; if ((aBlock[hMemNew].Next = Next) >0) { aBlock[Next].Prev = hMemNew; } aBlock[hMemNew].Prev = hMemIns; aBlock[hMemIns].Next = hMemNew; } /* Keep track of number of blocks and av. memory */ GUI_ALLOC.NumUsedBlocks++; GUI_ALLOC.NumFreeBlocks--; if (GUI_ALLOC.NumFreeBlocksMin > GUI_ALLOC.NumFreeBlocks) { GUI_ALLOC.NumFreeBlocksMin = GUI_ALLOC.NumFreeBlocks; } GUI_ALLOC.NumUsedBytes += size; GUI_ALLOC.NumFreeBytes -= size; if (GUI_ALLOC.NumFreeBytesMin > GUI_ALLOC.NumFreeBytes) { GUI_ALLOC.NumFreeBytesMin = GUI_ALLOC.NumFreeBytes; } return hMemNew; }
static GUI_HMEM _Alloc(int size) { GUI_HMEM hMemNew, hMemIns; CheckInit(); size = Size2LegalSize(size); /* Check if memory is available at all ...*/ if (size > GUI_ALLOC.NumFreeBytes) { GUI_DEBUG_WARN1("GUI_ALLOC_Alloc: Insufficient memory configured (Trying to alloc % bytes)", size); return 0; } /* Locate free handle */ if ((hMemNew = FindFreeHandle()) == 0) return 0; /* Locate or Create hole of sufficient size */ hMemIns = FindHole(size); #if GUI_ALLOC_AUTDEFRAG if (hMemIns == -1) { hMemIns = CreateHole(size); } #endif /* Occupy hole */ if (hMemIns==-1) { GUI_DEBUG_ERROROUT1("GUI_ALLOC_Alloc: Could not allocate %d bytes",size); return 0; } { int Off = aBlock[hMemIns].Off+aBlock[hMemIns].Size; int Next = aBlock[hMemIns].Next; aBlock[hMemNew].Size = size; aBlock[hMemNew].Off = Off; if ((aBlock[hMemNew].Next = Next) >0) { aBlock[Next].Prev = hMemNew; } aBlock[hMemNew].Prev = hMemIns; aBlock[hMemIns].Next = hMemNew; } /* Keep track of number of blocks and av. memory */ GUI_ALLOC.NumUsedBlocks++; GUI_ALLOC.NumFreeBlocks--; if (GUI_ALLOC.NumFreeBlocksMin > GUI_ALLOC.NumFreeBlocks) { GUI_ALLOC.NumFreeBlocksMin = GUI_ALLOC.NumFreeBlocks; } GUI_ALLOC.NumUsedBytes += size; GUI_ALLOC.NumFreeBytes -= size; if (GUI_ALLOC.NumFreeBytesMin > GUI_ALLOC.NumFreeBytes) { GUI_ALLOC.NumFreeBytesMin = GUI_ALLOC.NumFreeBytes; } /* In order to be on the safe side, zeroinit ! */ memset(HMEM2PTR(hMemNew), 0, size); return hMemNew; }
WM_HWIN WM_SelectWindow(WM_HWIN hWin) { WM_HWIN hWinPrev; WM_LOCK(); hWinPrev = GUI_Context.hAWin; if (hWin == 0) { hWin = WM__FirstWin; } if (!(WM_H2P(hWin)->Status & WM_SF_INUSE)) { GUI_DEBUG_ERROROUT1("Selecting invalid window", hWin); hWin=0; } /* Select new window */ GUI_Context.hAWin = hWin; WM__SetMaxClipRect(WM_H2P(hWin)); WM_UNLOCK(); return hWinPrev; }