#include "camtypes.h"
#include <errno.h>
#include "camelot.h"
Go to the source code of this file.
Defines | |
#define | MAX_BLOCK 0xFFFCL |
Functions | |
static BOOL | DoGrowGlobalHandle (HGLOBAL *pHandle, UINT32 OldSize, UINT32 NewSize, UINT32 MoreFlags, LPVOID *Pointer) |
Low-level private primitve for MemoryBlock::Grow. Actually does the work. Function does not exist if using VM_BLOCKs. |
|
Definition at line 116 of file memblk.cpp. |
|
Low-level private primitve for MemoryBlock::Grow. Actually does the work. Function does not exist if using VM_BLOCKs. static BOOL DoGrowGlobalHandle( HGLOBAL *pHandle, UINT32 OldSize, UINT32 NewSize, UINT32 MoreFlags, LPVOID *Pointer)
Definition at line 363 of file memblk.cpp. 00364 { 00365 if (GlobalUnlock( *pHandle )) 00366 { 00367 // if didn't unlock then we won't be able to realloc, so better stop now 00368 TRACE( wxT("GlobalUnlock failed in GrowGlobalHandle\n") ); 00369 return FALSE; 00370 } 00371 00372 // get Windows to grab us a new bigger block. Important to use GMEM_MOVEABLE as we want 00373 // our block to move if possible to satisfy the request 00374 HGLOBAL hNewHandle = GlobalReAlloc( *pHandle, NewSize, GMEM_MOVEABLE | MoreFlags ); 00375 00376 if (hNewHandle) 00377 { 00378 ADDR NewPtr = (ADDR)GlobalLock( hNewHandle ); 00379 if (NewPtr == NULL) 00380 { 00381 // careful here as we really do want to get our old data back - at the moment 00382 // all we have is a handle to an unlocked block of memory. To try and recover the 00383 // situation we'll try setting it back to its old size 00384 hNewHandle = GlobalReAlloc( hNewHandle, OldSize, GMEM_MOVEABLE ); 00385 if (hNewHandle) 00386 { 00387 NewPtr = (ADDR)GlobalLock( hNewHandle ); 00388 if (NewPtr) 00389 { 00390 // OK, got old data back but might be in different place so tidy up 00391 // then exit gracefully 00392 *Pointer = NewPtr; 00393 *pHandle = hNewHandle; 00394 TRACE( wxT("WARNING: Made hasty exit from GrowGlobalHandle\n") ); 00395 return FALSE; // indicate failure 00396 } 00397 } 00398 // this is very catastrophic - we cannot get our old data back, so 00399 // we will communicate this to the user. The program is likely to 00400 // crash and burn after this 00401 TRACE( wxT("DANGER: Catastrophic failure in GrowGlobalHandle\n") ); 00402 if (InformSeriousError( _R(IDE_BAD_GROWHEAP), _R(IDS_ABORT), _R(IDS_CONTINUE) ) == 1) 00403 AfxAbort(); 00404 00405 return FALSE; // although system is v. unstable 00406 } 00407 00408 TRACEUSER( "Andy", wxT("Handle %x changed to %x (%lx-%lx) (%ld-%ld) %x\n"), 00409 (INT32)*pHandle, (INT32)hNewHandle, 00410 (INT32)*Pointer, (INT32)NewPtr, 00411 (INT32)OldSize, (INT32)NewSize, 00412 (INT32)MoreFlags 00413 ); 00414 00415 // we've got our new block, update the callers variables 00416 *Pointer = NewPtr; 00417 *pHandle = hNewHandle; 00418 return TRUE; 00419 } 00420 00421 // couldn't reallocate it, the old one will still be there though 00422 TRACE( wxT("GlobalReAlloc failed in GrowGlobalHandle\n") ); 00423 TRACEUSER( "Andy", wxT("Failed to grow handle %x from %ld.%ld at %lx\n"), 00424 (INT32)*pHandle, 00425 (INT32)OldSize,(INT32)NewSize, 00426 (INT32)*Pointer 00427 ); 00428 00429 return FALSE; 00430 00431 }
|