Changeset 7728 for trunk/src/kernel32/os2heap.cpp
- Timestamp:
- Jan 6, 2002, 5:48:47 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/os2heap.cpp
r7360 r7728 1 /* $Id: os2heap.cpp,v 1.3 1 2001-11-16 14:52:55 phallerExp $ */1 /* $Id: os2heap.cpp,v 1.32 2002-01-06 16:48:47 sandervl Exp $ */ 2 2 3 3 /* 4 4 * Heap class for OS/2 5 5 * 6 * Copyright 1998 Sander van Leeuwen6 * Copyright 1998-2002 Sander van Leeuwen <sandervl@xs4all.nl> 7 7 * 8 8 * … … 10 10 * WINE controls depend on this, even though it apparently 11 11 * doesn't work like this in Windows. 12 * NOTE: Round up size to next 8 bytes boundary 13 * When reallocating memory block, don't use different 14 * memory block unless new size is larger than old size 15 * (rounded up to next 8 bytes boundary) 16 * (Verified this behaviour in NT4 (Global/Heap(Re)Alloc); 17 * fixes crashes in Opera 5.12 which relies on this 'feature') 12 18 * 13 19 * Project Odin Software License can be found in LICENSE.TXT … … 150 156 HEAPELEM *lpHeapObj; 151 157 LPVOID lpMem; 158 DWORD dwAllocBytes; 152 159 153 160 // dprintf(("OS2Heap::Alloc\n")); 154 lpMem = _umalloc(uheap, dwBytes + HEAP_OVERHEAD); 161 162 //size must be multiple of 8 bytes 163 dwAllocBytes = HEAP_ALIGN(dwBytes); 164 165 lpMem = _umalloc(uheap, dwAllocBytes + HEAP_OVERHEAD); 155 166 if(lpMem == NULL) { 156 167 dprintf(("OS2Heap::Alloc, lpMem == NULL")); … … 158 169 } 159 170 if(dwFlags & HEAP_ZERO_MEMORY) { 160 memset(lpMem, 0, dw Bytes+HEAP_OVERHEAD);171 memset(lpMem, 0, dwAllocBytes+HEAP_OVERHEAD); 161 172 } 162 173 163 174 #ifdef DEBUG 164 totalAlloc += dw Bytes;175 totalAlloc += dwAllocBytes; 165 176 #endif 166 177 167 178 //align at 8 byte boundary 168 lpHeapObj = (HEAPELEM *)(((ULONG)lpMem+7) & ~7);169 lpHeapObj->lpMem = lpMem;179 lpHeapObj = (HEAPELEM *)HEAP_ALIGN(lpMem); 180 lpHeapObj->lpMem = lpMem; 170 181 lpHeapObj->magic = MAGIC_NR_HEAP; 171 182 lpHeapObj->orgsize = dwBytes; //original size 183 lpHeapObj->cursize = dwBytes; //original size 184 172 185 return(LPVOID)(lpHeapObj+1); 173 186 } … … 194 207 return -1; 195 208 } 196 197 return(_msize(helem->lpMem) - HEAP_OVERHEAD); 209 return helem->cursize; //return current size of memory block 198 210 } 199 211 //****************************************************************************** … … 203 215 HEAPELEM *helem = GET_HEAPOBJ(lpMem); 204 216 LPVOID lpNewMem; 205 int i, oldSize;217 int i, maxSize; 206 218 207 219 if (dwBytes == 0) return NULL; // intercept stupid parameters … … 218 230 } 219 231 220 oldSize = Size(0,lpMem); 221 if (oldSize >= dwBytes) { 222 dprintf(("ReAlloc with smaller size than original (%d); return old pointer", oldSize)); 232 maxSize = HEAP_ALIGN(helem->orgsize); 233 if (dwBytes <= maxSize) { 234 dprintf(("ReAlloc with smaller size than original (%d); return old pointer", maxSize)); 235 //update current size so HeapSize will return the right value 236 helem->cursize = dwBytes; 223 237 return lpMem; // if reallocation with same size don't do anything 224 238 } 225 239 lpNewMem = Alloc(dwFlags, dwBytes); 226 memcpy(lpNewMem, lpMem, dwBytes < oldSize ? dwBytes : oldSize);240 memcpy(lpNewMem, lpMem, dwBytes < maxSize ? dwBytes : maxSize); 227 241 Free(0, lpMem); 228 242
Note:
See TracChangeset
for help on using the changeset viewer.