pointer CGAlloc( size_t size ) /****************************/ { pointer chunk; _MemLow; for( ;; ) { #if _MEMORY_TRACKING & _FULL_TRACKING chunk = _trmem_alloc( size, _trmem_guess_who(), Handle ); #else chunk = _SysAlloc( size ); #endif if( chunk != NULL ) { #if _MEMORY_TRACKING & _CHUNK_TRACKING ++Chunks; #endif _AlignmentCheck( chunk, 8 ); return( chunk ); } if( !_MemCheck( size ) ) { break; } } if( ( MemOut == MO_FATAL ) || ( InOptimizer != 0 ) ) { FatalError( "Out of memory" ); } else if( MemOut == MO_SUICIDE ) { Suicide(); } return( NULL ); }
void *WRAPI WRMemAlloc( size_t size ) { #ifdef TRMEM return( _trmem_alloc( size, _trmem_guess_who(), TRMemHandle ) ); #else return( malloc( size ) ); #endif }
extern void * TRMemAlloc( size_t size ) /*************************************/ { #ifdef TRMEM return( _trmem_alloc( size, _trmem_guess_who(), TRMemHandle ) ); #else return( malloc( size ) ); #endif }
void *MemAllocGlobal( size_t size ) /*********************************/ { void *ptr; #ifdef TRMEM ptr = _trmem_alloc( size, _trmem_guess_who(), TRMemHandle ); #else ptr = malloc( size ); #endif if( ptr == NULL && size != 0 ) FatalError( ERR_NO_MEMORY ); return( ptr ); }
void *AsmAlloc( size_t size ) { void *ptr; #ifdef TRMEM ptr = _trmem_alloc( size, _trmem_guess_who(), memHandle ); #else ptr = malloc( size ); #endif if( ptr == NULL ) { Fatal( MSG_OUT_OF_MEMORY ); } return( ptr ); }
void *MAlloc( size_t size ) { void *p; #ifdef TRMEM p = _trmem_alloc( size, _trmem_guess_who(), TRMemHandle ); #else p = malloc( size ); #endif if( p == NULL ) { Fatal( "Out of memory!\n" ); } return( p ); }
void *MemAlloc( size_t size ) { void *p; #ifdef TRMEM p = _trmem_alloc( size, _trmem_guess_who(), TRMemHandle ); #else p = malloc( size ); #endif if( p != NULL ) { memset( p, 0, size ); } return( p ); }
void *operator new( size_t size ) /*******************************/ { void *p; #ifdef TRACKER _trmem_who caller; caller = _trmem_guess_who(); #endif #ifdef TRACKER p = _trmem_alloc( size, _trmem_guess_who(), TrHdl ); #else p = malloc( size ); #endif return p; }
void *RcMemMalloc( size_t size ) /******************************/ { void * ptr; #ifdef RC_USE_TRMEM ptr = _trmem_alloc( size, _trmem_guess_who(), RcMemHandle ); #else ptr = RCMemLayer1Malloc( size ); #endif if (ptr == NULL) { RcFatalError( ERR_OUT_OF_MEMORY ); } return( ptr ); }
void * WBRAlloc( size_t size ) /****************************/ // note: code directly cloned from above since we need to be able to trace // calling functions when the memory tracker is in. { void *p; #ifdef TRACKER _trmem_who caller; caller = _trmem_guess_who(); #endif #ifdef TRACKER p = _trmem_alloc( size, _trmem_guess_who(), TrHdl ); #else p = malloc( size ); #endif return p; }
/* * getMem - get and clear memory */ static void *getMem( size_t size, WHO_PTR who ) { void *tmp; #ifdef TRMEM tmp = _trmem_alloc( size, who, trmemHandle ); #else who = who; tmp = malloc( size ); #endif if( tmp != NULL ) { #ifdef __WATCOMC__ size = MSIZE( tmp ); #endif memset( tmp, 0, size ); } return( tmp ); } /* getMem */
void *operator new( size_t size ) /*******************************/ { void *p; #ifdef TRACKER _trmem_who caller; caller = _trmem_guess_who(); #endif // for(;;) { #ifdef TRACKER p = _trmem_alloc( size, _trmem_guess_who(), TrHdl ); #else p = malloc( size ); #endif // if( p != NULL || !DRSwap() ) break; //only for browser // } return p; }
void *MemAlloc( size_t size ) /***************************/ { MemPtr *ptr; if( size == 0 ) { return( NULL ); } #ifdef TRMEM ptr = _trmem_alloc( size + sizeof( MemPtr ), _trmem_guess_who(), TRMemHandle ); #else ptr = malloc( size + sizeof( MemPtr ) ); #endif if( ptr == NULL ) FatalError( ERR_NO_MEMORY ); ptr->next = memPtr; ptr->prev = NULL; if( memPtr ) { memPtr->prev = ptr; } memPtr = ptr; return( ptr + 1 ); }
void *LAlloc( size_t size ) #endif { void *p; for( ;; ) { #ifdef TRMEM p = _trmem_alloc( size, ra, TrHdl ); #else p = malloc( size ); #endif if( p != NULL ) { memset( p, 0, size ); break; } if( !FreeUpMemory() ) break; } #ifdef _INT_DEBUG if( p != NULL ) ++Chunks; #endif return( p ); }
static void * TRMemAlloc( size_t size ) /*************************************/ { return( _trmem_alloc( size, _trmem_guess_who(), TRMemHandle ) ); }
void *LAlloc( size_t size ) /*************************/ #endif { void *p; for( ;; ) { #ifdef TRMEM p = _trmem_alloc( size, ra, TrHdl ); #elif defined( USE_OS2HMALLOC ) /* Use all but 64MB of available low memory address space and then use available high memory. Os2_private_mem_left is a good enough estimate of address space remaining in the lower private arena. The goal is to leave a large chunk of address space available for the HLL_SECT_MISC section which is allocated at the end of pass1 after most of the other memory allocations have been done */ if( os2_private_mem_left > 64 * 1024 * 1024 && size + 16 < os2_private_mem_left ) { p = malloc( size ); if( p ) os2_private_mem_left -= size + 16; } else { p = _os2hmalloc( size ); } #elif defined( OS2_MEM_HDR_MAGIC ) /* * On OS/2 we will try use high memory when available. OS/2 has * two arenas for private memory, the Open Watcom heap is currently * only using the lower one. The lower arena is often smaller than * 128MB because of fragmentation caused by big applications (like * mozilla, openoffice, ..) in the shared arena above it. The high * arena on the other hand, is usually not subject to this kind of * fragmentation and will normally be able to provide more than * 400MB of contiguous virtual memory. Big links needs lots of * memory, so for medium/large allocations we try use the high memory. * * The allocations are identified by being at a fixed offset (16) into * a page and the header values (the 3 magics and the page aligned size). */ static int fObjAny = -1; /* -1 = check, 0 = no upper, 1 = have upper */ static size_t minUpperAlloc = 0x2000; /* 8 KBytes */ if( fObjAny && size >= minUpperAlloc ) { APIRET rc; ULONG ul; /* * Check if can allocate more than 512MB on the first call. * Will fail if upper arena does not exist. */ if( fObjAny == -1) { rc = DosQuerySysInfo( QSV_VIRTUALADDRESSLIMIT, QSV_VIRTUALADDRESSLIMIT, &ul, sizeof( ul ) ); fObjAny = rc == NO_ERROR && ul > 512 /*MB*/; if( !fObjAny ) continue; /* restart the loop */ } /* Try allocate a block in the high arena. */ ul = size + sizeof( os2_mem_hdr ); /* Make room for header */ ul = ( ul + 0xfff ) & ~0xfffUL; /* Round up to 4K boundary */ rc = DosAllocMem( &p, ul, OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT ); if( rc == NO_ERROR && (uintptr_t)p >= 0x20000000UL /* 512MB */) { /* Mark allocation as coming from upper arena */ os2_mem_hdr *hdr = (os2_mem_hdr *)p; hdr->magic = hdr->magic1 = hdr->magic2 = OS2_MEM_HDR_MAGIC; hdr->size = ul; p = hdr + 1; break; /* return pointer to caller */ } if( rc == ERROR_INVALID_PARAMETER ) fObjAny = FALSE; /* Upper arena not supported */ else if( rc == NO_ERROR ) DosFreeMem( p ); /* Came for lower area - give back */ } p = malloc( size ); /* If lower arena allocation failed try upper arena unless time to die */ if( p == NULL && fObjAny == TRUE && minUpperAlloc > 0x2000 ) { minUpperAlloc >>= 1; /* Halve if more than 8192 */ continue; /* Try again */ } #else /* ! OS2_MEM_HDR_MAGIC */ p = malloc( size ); #endif if( p != NULL ) { memset( p, 0, size ); break; } /* Try to free up some memory and try malloc */ if( !FreeUpMemory() ) break; } /* for */