OWindow::~OWindow() { destroy(); #ifdef __IBMCPP__ _heapmin(); // return all unused memory to OS/2 #endif }
IDEBool IDEAPI IDERunYourSelf // COMPILE A PROGRAM ( IDEDllHdl hdl // - handle for this instantiation , const char* opts // - options , IDEBool* fatal_error ) { // - addr[fatality indication] //**************************** // Do a compile of a file //**************************** jmp_buf env; char infile[_MAX_PATH]; // - input file name char outfile[4 + _MAX_PATH]; // - output file name (need room for "-fo=") char *argv[4]; int ret; hdl = hdl; TBreak(); // clear any pending IDEStopRunning's *fatal_error = FALSE; FatalEnv = &env; if( (ret = setjmp( env )) != 0 ) { /* if fatal error has occurred */ *fatal_error = TRUE; } else { argv[0] = (char *)opts; argv[1] = NULL; getFrontEndArgv( argv, 0, infile, outfile ); ret = FrontEnd( argv ); } #if HEAP_CHK == 1 heap_check(); #endif #ifdef __OS2__ _heapmin(); #endif return( ret != 0 ); }
void SetV86(void (*f)()) { #ifdef __MSC__ _heapmin(); #endif SetTSS( (TSS *)&v86tss, seg.cs, seg.ds, f, 0x23002L, (unsigned char *) sbrk(0)+2048, seg.ss, stack+STACKSIZE, 0x10); v86tss.tss.iobase = v86tss.iomap -(unsigned char *)&v86tss; memset(v86tss.iomap, 0, sizeof(v86tss.iomap)); v86tss.iomap[8192]=0xff; ProtoTssSel = AllocSel(); SetSegDesc(ProtoTssSel, SegToLinier(seg.ds, (unsigned short) &tss), (long) sizeof(TSS), TypeTSS, SmallSeg, 0); V86TssSel = AllocSel(); SetSegDesc(V86TssSel, SegToLinier(seg.ds, (unsigned short) &v86tss), (long) sizeof(TSS_IO), TypeTSS, SmallSeg, 0); IntHandler = v86int; }
bool VGui_InitInterfacesList( const char *moduleName, CreateInterfaceFn *factoryList, int numFactories ) { g_nYou_Must_Add_Public_Vgui_Controls_Vgui_ControlsCpp_To_Your_Project = 1; // If you hit this error, then you need to include memoverride.cpp in the project somewhere or else // you'll get crashes later when vgui_controls allocates KeyValues and vgui tries to delete them. #if !defined(NO_MALLOC_OVERRIDE) if ( _heapmin() != 1 ) { Assert( false ); Error( "Must include memoverride.cpp in your project." ); } #endif // keep a record of this module name strncpy(g_szControlsModuleName, moduleName, sizeof(g_szControlsModuleName)); g_szControlsModuleName[sizeof(g_szControlsModuleName) - 1] = 0; // initialize our locale (must be done for every vgui dll/exe) // "" makes it use the default locale, required to make iswprint() work correctly in different languages setlocale(LC_CTYPE, ""); setlocale(LC_TIME, ""); setlocale(LC_COLLATE, ""); setlocale(LC_MONETARY, ""); // NOTE: Vgui expects to use these interfaces which are defined in tier3.lib if ( !g_pVGui || !g_pVGuiInput || !g_pVGuiPanel || !g_pVGuiSurface || !g_pVGuiSchemeManager || !g_pVGuiSystem ) { Warning( "vgui_controls is missing a required interface!\n" ); return false; } return true; }
static void destroyLWObject(LWObject *Object) { int p,i; if(Object) { if(Object->pols) { for(p=0; p<Object->nPols; p++) if((Object->pols[p]).plist) free((Object->pols[p]).plist); free(Object->pols); } if(Object->pnts) { free(Object->pnts); } if(Object->surfs) { for(i=0; i<Object->nSurfs; i++) if(Object->surfs[i].size) if(Object->surfs[i].data) free(Object->surfs[i].data); free(Object->surfs); } free(Object); #ifdef HEAP_PROBLEM _heapmin(); #endif } }
VOID StandardHeap::compact(VOID) { if (freed) { freed = FALSE; _heapmin(); } }
void IDEAPI IDEFreeHeap( void ) { //************************************* //Cleanup Heap //************************************* #ifdef __WATCOMC__ _heapmin(); #endif }
main(int argc, char *argv[]) { clock_t clock(),starttime; int status, i; if (argc < 2) { printf("Time execution of a command.\nUse:\n\ttimer command\n"); exit(1); } argv[argc] = 0; /* terminate with a 0 (unportable method) */ starttime = clock(); /* ** This block added to keep arguments with embedded whitespace from getting ** broken up when timing is done. A *nix version should be a bit different. ** Also, the assignment to argv[i] technically isn't portable, but I don't ** know of an implementation where it causes a problem. <JC> */ for (i=1;i<argc;i++) { if (NULL != strchr(argv[i], ' ')) { size_t len = strlen(argv[i]+3); char *temp = malloc(len); strcpy(temp+1, argv[i]); temp[0] = '"'; temp[len-2] = '"'; temp[len-1] = '\0'; argv[i] = temp; } } /* This reduces memory usage with MS compilers by releasing unused heap. * Watcom may support it as well, but I'm not sure. */ #if defined(_QC) || defined(_MSC_VER) _heapmin(); #endif status = spawnvp(0,argv[1],SVP_CAST(argv + 1)); starttime = clock() - starttime; if (status == -1) { printf("'%s' failed to execute\n",argv[1]); exit(1); } #if !defined(__TURBOC__) printf("Elapsed time = %d.%02d seconds\n",(int) (starttime/CLK_TCK), (int) (starttime%CLK_TCK)); #else printf("Elapsed time = %.2f seconds\n", starttime/CLK_TCK); #endif if (status != 0) printf("--- errorlevel %d\n",status); /* exit(0); changed to `return 0;' to reduce program size (minutely) * and possibility or warnings that main doesn't return a value. */ return 0; }
static PyObject * msvcrt_heapmin_impl(PyModuleDef *module) /*[clinic end generated code: output=464f866feb57c436 input=82e1771d21bde2d8]*/ { if (_heapmin() != 0) return PyErr_SetFromErrno(PyExc_IOError); Py_RETURN_NONE; }
// Force the malloc heap to clean itself up, and free unused blocks // back to the OS. (According to the docs, only works on NT.) static PyObject *msvcrt_heapmin(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, ":heapmin")) return NULL; if (_heapmin() != 0) return PyErr_SetFromErrno(PyExc_IOError); Py_INCREF(Py_None); return Py_None; }
void xrMemory::mem_compact () { RegFlushKey ( HKEY_CLASSES_ROOT ); RegFlushKey ( HKEY_CURRENT_USER ); if (g_allow_heap_min) _heapmin ( ); HeapCompact (GetProcessHeap(),0); if (g_pStringContainer) g_pStringContainer->clean (); if (g_pSharedMemoryContainer) g_pSharedMemoryContainer->clean (); if (strstr(Core.Params,"-swap_on_compact")) SetProcessWorkingSetSize (GetCurrentProcess(),size_t(-1),size_t(-1)); }
MemoryDevice::~MemoryDevice() { if (m_fOwnsPieces) { // All pieces are assumed to be BYTE arrays. for (int nPiece = 0; nPiece < m_Pieces.count(); nPiece++) { delete [] (LPBYTE)((MEMORY_DEVICE_PIECE*)m_Pieces.get_element(nPiece))->m_pData; } // A little heap compaction test. _heapmin(); } }
VOID clbDestroyProc(PCLBOX pclb) { if (pclb) { if (pclb->hchk) WinDestroyWindow(pclb->hchk); WinDestroyWindow(pclb->hlbx); WinDestroyWindow(pclb->hentry); WinDestroyWindow(pclb->hadd); WinDestroyWindow(pclb->hrem); WinDestroyWindow(pclb->hfind); free(pclb->psz); free(pclb); _heapmin(); } /* endif */ }
void FreeExcludes (char ***ex,int *nex) { int x; if(ex && *ex) { for(x = 0;(*ex)[x];x++) free((*ex)[x]); free(*ex); _heapmin(); } if(nex) *nex = 0; if(ex) *ex = NULL; }
/** * cairo_os2_fini: * * Uninitializes the Cairo library. This function is automatically called if * Cairo was compiled to be a DLL (however it's not a problem if it's called * multiple times). But if you link to Cairo statically, you have to call it * once to shut down Cairo, to let it free all the resources it has allocated. * * Since: 1.4 **/ cairo_public void cairo_os2_fini (void) { /* This has to uninitialize some stuffs, like destroy mutex semaphores etc.. */ if (cairo_os2_initialization_count <= 0) return; cairo_os2_initialization_count--; if (cairo_os2_initialization_count > 0) return; DisableFPUException (); cairo_debug_reset_static_data (); #if CAIRO_HAS_FC_FONT # if HAVE_FCFINI /* Uninitialize FontConfig */ FcFini (); # endif #endif #ifdef __WATCOMC__ /* It can happen that the libraries we use have memory leaks, * so there are still memory chunks allocated at this point. * In these cases, Watcom might still have a bigger memory chunk, * called "the heap" allocated from the OS. * As we want to minimize the memory we lose from the point of * view of the OS, we call this function to shrink that heap * as much as possible. */ _heapshrink (); #else /* GCC has a heapmin function that approximately corresponds to * what the Watcom function does */ _heapmin (); #endif }
void IDEAPI IDEFreeHeap( void ) { #ifdef __WATCOMC__ _heapmin(); #endif }
static LWObject *createLWObject(const char *name) { char sname[MAX_SURFNAME]; LWOBInfo LWObj; LWPoint pnt; LWObject *Object=NULL; LWSurface surf; int p; surf.name = sname; surf.data = NULL; surf.size = 0; if(!OpenLWObject((char *)name,&LWObj)) return(NULL); if(Object=malloc(sizeof(LWObject)+strlen(name)+2) ) { memset(Object,0,sizeof(LWObject)); Object->name = (char *)&(Object[1]); strcpy(Object->name,name); while(GetPolygon(&LWObj,&MaxPoly)==1) Object->nPols++; ResetPosition(&LWObj); if(Object->pols = calloc(sizeof(LWPolygon),Object->nPols)) { for(p=0; (p<Object->nPols) && (GetPolygon(&LWObj,&MaxPoly)==1); p++ ) copyPolygon(&(Object->pols[p]), &MaxPoly); } while(GetPoint(&LWObj,&pnt)==1) Object->nPnts++; ResetPosition(&LWObj); if(Object->pnts = calloc(sizeof(LWPoint),Object->nPnts)) { double r; for(p=0; (p<Object->nPnts) && (GetPoint(&LWObj,&pnt)==1); p++ ) { if(p) { if(pnt.x>Object->bounds[BB_XMAX]) Object->bounds[BB_XMAX] = pnt.x; if(pnt.x<Object->bounds[BB_XMIN]) Object->bounds[BB_XMIN] = pnt.x; if(pnt.y>Object->bounds[BB_YMAX]) Object->bounds[BB_YMAX] = pnt.y; if(pnt.y<Object->bounds[BB_YMIN]) Object->bounds[BB_YMIN] = pnt.y; if(pnt.z>Object->bounds[BB_ZMAX]) Object->bounds[BB_ZMAX] = pnt.z; if(pnt.z<Object->bounds[BB_ZMIN]) Object->bounds[BB_ZMIN] = pnt.z; r = sqrt(pnt.x*pnt.x + pnt.y*pnt.y + pnt.z*pnt.z); if(Object->rMax<r) Object->rMax = r; } else // initialize max values = first values { Object->rMax = sqrt(pnt.x*pnt.x + pnt.y*pnt.y + pnt.z*pnt.z); Object->bounds[BB_XMIN] = Object->bounds[BB_XMAX] = pnt.x; Object->bounds[BB_YMIN] = Object->bounds[BB_YMAX] = pnt.y; Object->bounds[BB_ZMIN] = Object->bounds[BB_ZMAX] = pnt.z; } Object->pnts[p] = pnt; } while(GetSurface(&LWObj,&surf)==1) Object->nSurfs++; if(Object->surfs = malloc( LWObj.srfSize+(sizeof(LWSurface)*(Object->nSurfs+1)) )) { int i,len,siz; fpos_t datpos; char *buf = (char *)&(Object->surfs[Object->nSurfs+1]); memset(Object->surfs,0,( LWObj.srfSize + (sizeof(LWSurface)*(Object->nSurfs+1)) )); GetSRF(&LWObj,buf,LWObj.srfSize); for(i=0; i<Object->nSurfs; i++) { Object->surfs[i].name = buf; Object->surfs[i].size = 0; Object->surfs[i].data = NULL; if( (siz=GetSDatSize(&LWObj,buf,&datpos)) ) { if( (Object->surfs[i].data=malloc(siz)) ) { GetSDat(&LWObj,Object->surfs[i].data,siz,&datpos); Object->surfs[i].size = siz; } } len = strlen(buf) + 1; // get NULL too if(len&1) len++; buf += len; } Object->surfs[i].name = NULL; } } } CloseLWObject(&LWObj); #ifdef HEAP_PROBLEM _heapmin(); #endif return(Object); }