FILE* ON_Workspace::OpenFile( const wchar_t* sFileName, const wchar_t* sMode ) { FILE* pFile = ON::OpenFile( sFileName, sMode ); if ( pFile ) { struct ON_Workspace_FBLK* pFileBlk = (struct ON_Workspace_FBLK*)GetMemory( sizeof(*pFileBlk) ); pFileBlk->pNext = m_pFileBlk; pFileBlk->pFile = pFile; m_pFileBlk = pFileBlk; } return pFile; }
//删除协议上下文 void IAppInterface::DeleteProtocolContext(ProtocolContext *context) { //释放protocol实例 IProtocolFactory *factory = GetProtocolFactory(); if(context->protocol != NULL) factory->DeleteProtocol(context->protocol_type, context->protocol); IMemory *memory = GetMemory(); assert(context!=NULL); context->~ProtocolContext(); memory->Free((void*)context, sizeof(ProtocolContext)); }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== node_t *AllocNode (void) { node_t *node; node = GetMemory(sizeof(*node)); memset (node, 0, sizeof(*node)); if (numthreads == 1) { c_nodememory += MemorySize(node); } //end if return node; } //end of the function AllocNode
void *GetClearedMemory(unsigned long size) #endif //MEMDEBUG { void *ptr; #ifdef MEMDEBUG ptr = GetMemoryDebug(size, label, file, line); #else ptr = GetMemory(size); #endif //MEMDEBUG memset(ptr, 0, size); return ptr; }
void InternalAllocator::ReleaseAllMemory() { std::lock_guard<std::mutex> l(m_PagesMutex); // walk all pages backwards and kill them Page* next = m_Tail; while(next) { auto current = next; next = current->GetPrevious(); current->~Page(); m_ExternalAllocator->Deallocate(current->GetMemory()); } }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== libvar_t *LibVarAlloc( char *var_name ) { libvar_t *v; v = (libvar_t *) GetMemory( sizeof( libvar_t ) + strlen( var_name ) + 1 ); memset( v, 0, sizeof( libvar_t ) ); v->name = (char *) v + sizeof( libvar_t ); strcpy( v->name, var_name ); //add the variable in the list v->next = libvarlist; libvarlist = v; return v; } //end of the function LibVarAlloc
/* Alloc UNDO/REDO structures */ void InitUndo() { // Check MaxUndo global var. if ( MaxUndo < 1 ) MaxUndo = 1; // Allocates MaxUndo+1 entries if ( UndoArray == NULL ) UndoArray = (UndoData *)GetMemory (MaxUndo * sizeof(UndoData)); NbUndo = 0; NextUndo = -1; }
/************************************************************** 功能:从 src 中分析出网页链接,并加入到当前节点的子节点上 ***************************************************************/ void GetLink(char * src) { char * pa, * pb, * pc; char * myanchor = 0; int len = 0; pa = src; do { if((pb = strstr(pa, "href='"))) { pc = strchr(pb + 6, '\''); len = strlen(pb + 6) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 6, len); } else if((pb = strstr(pa, "href=\""))) { pc = strchr(pb + 6, '"'); len = strlen(pb + 6) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 6, len); } else if((pb = strstr(pa, "href="))) { GetAfterPosWithSlash(pb + 5, &pc); len = strlen(pb + 5) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 5, len); } else {goto __returnLink ;} if(strlen(myanchor) > 0) AddChildNode(NodeCurr, myanchor); if(pc + 1) pa = pc + 1; }while(pa); __returnLink: return; }
/************************************************************** 功能:从 src 中分析出网页链接,并加入到当前节点的子节点上 ***************************************************************/ void GetLink(char * src) { char * pa, * pb, * pc; char * myanchor = 0; int len = 0; pa = src; do { if((pb = strstr(pa, "href='"))) { pc = strchr(pb + 6, '\''); len = strlen(pb + 6) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 6, len); } else if((pb = strstr(pa, "href=\""))) { pc = strchr(pb + 6, '"'); len = strlen(pb + 6) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 6, len); } else if((pb = strstr(pa, "href="))) { GetAfterPosWithSlash(pb + 5, &pc); len = strlen(pb + 5) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 5, len); } else {goto __returnLink ;} /* if(DEBUG) { if(strcmp(NodeCurr->dir, "/")) fprintf(stdout, "%s\thttp://%s/%s/%s\n", myanchor, NodeCurr->host, NodeCurr->dir, strcmp(NodeCurr->page, "`")?NodeCurr->page:""); else fprintf(stdout, "%s\thttp://%s%s%s\n", myanchor, NodeCurr->host, NodeCurr->dir, strcmp(NodeCurr->page, "`")?NodeCurr->page:""); } */ if(strlen(myanchor) > 0) AddChildNode(NodeCurr, myanchor); if(pc + 1) pa = pc + 1; }while(pa); __returnLink: return; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AAS_UpdateStringIndexes( int numconfigstrings, char *configstrings[] ) { int i; //set string pointers and copy the strings for ( i = 0; i < numconfigstrings; i++ ) { if ( configstrings[i] ) { //if ((*aasworld).configstrings[i]) FreeMemory((*aasworld).configstrings[i]); ( *aasworld ).configstrings[i] = (char *) GetMemory( strlen( configstrings[i] ) + 1 ); strcpy( ( *aasworld ).configstrings[i], configstrings[i] ); } //end if } //end for ( *aasworld ).indexessetup = qtrue; } //end of the function AAS_UpdateStringIndexes
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AddThread( void ( *func )(int) ) { thread_t *thread; if ( numthreads == 1 ) { if ( currentnumthreads >= numthreads ) { return; } currentnumthreads++; func( -1 ); currentnumthreads--; } //end if else { ThreadLock(); if ( currentnumthreads >= numthreads ) { ThreadUnlock(); return; } //end if //allocate new thread thread = GetMemory( sizeof( thread_t ) ); if ( !thread ) { Error( "can't allocate memory for thread\n" ); } // thread->threadid = currentthreadid; thread->handle = CreateThread( NULL, // LPSECURITY_ATTRIBUTES lpsa, 0, // DWORD cbStack, (LPTHREAD_START_ROUTINE)func, // LPTHREAD_START_ROUTINE lpStartAddr, (LPVOID) thread->threadid, // LPVOID lpvThreadParm, 0, // DWORD fdwCreate, &thread->id ); //add the thread to the end of the list thread->next = NULL; if ( lastthread ) { lastthread->next = thread; } else { firstthread = thread;} lastthread = thread; // #ifdef THREAD_DEBUG qprintf( "added thread with id %d\n", thread->threadid ); #endif //THREAD_DEBUG // currentnumthreads++; currentthreadid++; // ThreadUnlock(); } //end else } //end of the function AddThread
//=========================================================================== // returns pointer to file handle // sets offset to and length of 'filename' in the pak file // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== qboolean FindFileInPak( char *pakfile, char *filename, foundfile_t *file ) { FILE *fp; dpackheader_t packheader; dpackfile_t *packfiles; int numdirs, i; char path[MAX_PATH]; //open the pak file fp = fopen( pakfile, "rb" ); if ( !fp ) { return false; } //end if //read pak header, check for valid pak id and seek to the dir entries if ( ( fread( &packheader, 1, sizeof( dpackheader_t ), fp ) != sizeof( dpackheader_t ) ) || ( packheader.ident != IDPAKHEADER ) || ( fseek( fp, LittleLong( packheader.dirofs ), SEEK_SET ) ) ) { fclose( fp ); return false; } //end if //number of dir entries in the pak file numdirs = LittleLong( packheader.dirlen ) / sizeof( dpackfile_t ); packfiles = (dpackfile_t *) GetMemory( numdirs * sizeof( dpackfile_t ) ); //read the dir entry if ( fread( packfiles, sizeof( dpackfile_t ), numdirs, fp ) != numdirs ) { fclose( fp ); FreeMemory( packfiles ); return false; } //end if fclose( fp ); // strcpy( path, filename ); ConvertPath( path ); //find the dir entry in the pak file for ( i = 0; i < numdirs; i++ ) { //convert the dir entry name ConvertPath( packfiles[i].name ); //compare the dir entry name with the filename if ( Q_strcasecmp( packfiles[i].name, path ) == 0 ) { strcpy( file->filename, pakfile ); file->offset = LittleLong( packfiles[i].filepos ); file->length = LittleLong( packfiles[i].filelen ); FreeMemory( packfiles ); return true; } //end if } //end for FreeMemory( packfiles ); return false; } //end of the function FindFileInPak
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void PS_CreatePunctuationTable(script_t *script, punctuation_t *punctuations) { int i; punctuation_t *p, *lastp, *newp; //get memory for the table if (!script->punctuationtable) { script->punctuationtable = (punctuation_t **) GetMemory(256 * sizeof(punctuation_t *)); } memset(script->punctuationtable, 0, 256 * sizeof(punctuation_t *)); //add the punctuations in the list to the punctuation table for (i = 0; punctuations[i].p; i++) { newp = &punctuations[i]; lastp = NULL; //sort the punctuations in this table entry on length (longer punctuations first) for (p = script->punctuationtable[(unsigned int) newp->p[0]]; p; p = p->next) { if (strlen(p->p) < strlen(newp->p)) { newp->next = p; if (lastp) { lastp->next = newp; } else { script->punctuationtable[(unsigned int) newp->p[0]] = newp; } break; } //end if lastp = p; } //end for if (!p) { newp->next = NULL; if (lastp) { lastp->next = newp; } else { script->punctuationtable[(unsigned int) newp->p[0]] = newp; } } //end if } //end for } //end of the function PS_CreatePunctuationTable
struct Node *CreateNode(struct Seg *ts, const bbox_t bbox) { struct Node *tn; struct Seg *rights = NULL; struct Seg *lefts = NULL; tn = GetMemory( sizeof( struct Node)); /* Create a node*/ DivideSegs(ts,&rights,&lefts,bbox); /* Divide node in two*/ num_nodes++; tn->x = node_x; /* store node line info*/ tn->y = node_y; tn->dx = node_dx; tn->dy = node_dy; FindLimits(lefts,tn->leftbox); /* Find limits of vertices */ if(IsItConvex(lefts)) /* Check lefthand side*/ { if (verbosity > 1) Verbose("L"); tn->nextl = CreateNode(lefts,tn->leftbox); /* still segs remaining*/ tn->chleft = 0; if (verbosity > 1) Verbose("\b"); } else { tn->nextl = NULL; tn->chleft = CreateSSector(lefts) | 0x8000; } FindLimits(rights, tn->rightbox); /* Find limits of vertices*/ if(IsItConvex(rights)) /* Check righthand side*/ { if (verbosity > 1) Verbose("R"); tn->nextr = CreateNode(rights, tn->rightbox); /* still segs remaining*/ tn->chright = 0; if (verbosity > 1) Verbose("\b"); } else { tn->nextr = NULL; tn->chright = CreateSSector(rights) | 0x8000; } return tn; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AddThread( void ( *func )(int) ) { thread_t *thread; if ( numthreads == 1 ) { if ( currentnumthreads >= numthreads ) { return; } currentnumthreads++; func( -1 ); currentnumthreads--; } //end if else { ThreadLock(); if ( currentnumthreads >= numthreads ) { ThreadUnlock(); return; } //end if //allocate new thread thread = GetMemory( sizeof( thread_t ) ); if ( !thread ) { Error( "can't allocate memory for thread\n" ); } // thread->threadid = currentthreadid; thread->id = sprocsp( ( void( * ) ( void *, size_t ) )func, PR_SALL, (void *)thread->threadid, NULL, 0x100000 ); if ( thread->id == -1 ) { perror( "sproc" ); Error( "sproc failed" ); } //add the thread to the end of the list thread->next = NULL; if ( lastthread ) { lastthread->next = thread; } else { firstthread = thread;} lastthread = thread; // #ifdef THREAD_DEBUG qprintf( "added thread with id %d\n", thread->threadid ); #endif //THREAD_DEBUG // currentnumthreads++; currentthreadid++; // ThreadUnlock(); } //end else } //end of the function AddThread
void list<T>::push_back(T t) { void* mem = GetMemory(sizeof(node)); node* add = new (reinterpret_cast<yassl_pointer>(mem)) node(t); if (tail_) { tail_->next_ = add; add->prev_ = tail_; } else head_ = add; tail_ = add; ++sz_; }
void list<T>::push_front(T t) { void* mem = GetMemory(sizeof(node)); node* add = new (reinterpret_cast<yassl_pointer>(mem)) node(t); if (head_) { add->next_ = head_; head_->prev_ = add; } else tail_ = add; head_ = add; ++sz_; }
status_t BnMemory::Transact( uint32_t code, SParcel& data, SParcel* reply, uint32_t flags) { if (code == kGetMemory) { ssize_t offset, size; sptr<IMemoryHeap> heap = GetMemory(&offset, &size); reply->WriteBinder(heap->AsBinder()); reply->WriteInt32(offset); reply->WriteInt32(size); return B_OK; } return BBinder::Transact(code, data, reply, flags); }
void SetKeyValue( entity_t *ent, char *key, char *value ) { epair_t *ep; for ( ep = ent->epairs ; ep ; ep = ep->next ) if ( !strcmp( ep->key, key ) ) { FreeMemory( ep->value ); ep->value = copystring( value ); return; } ep = GetMemory( sizeof( *ep ) ); ep->next = ent->epairs; ent->epairs = ep; ep->key = copystring( key ); ep->value = copystring( value ); }
void Dlg_MemBookmark::ImportFromFile( std::string sFilename ) { FILE* pFile = nullptr; errno_t nErr = fopen_s( &pFile, sFilename.c_str(), "r" ); if ( pFile != nullptr ) { Document doc; doc.ParseStream( FileStream( pFile ) ); if ( !doc.HasParseError() ) { if ( doc.HasMember( "Bookmarks" ) ) { ClearAllBookmarks(); const Value& BookmarksData = doc[ "Bookmarks" ]; for ( SizeType i = 0; i < BookmarksData.Size(); ++i ) { MemBookmark* NewBookmark = new MemBookmark(); wchar_t buffer[ 256 ]; swprintf_s ( buffer, 256, L"%s", Widen( BookmarksData[ i ][ "Description" ].GetString() ).c_str() ); NewBookmark->SetDescription ( buffer ); NewBookmark->SetAddress( BookmarksData[ i ][ "Address" ].GetUint() ); NewBookmark->SetType( BookmarksData[ i ][ "Type" ].GetInt() ); NewBookmark->SetDecimal( BookmarksData[ i ][ "Decimal" ].GetBool() ); NewBookmark->SetValue( GetMemory( NewBookmark->Address(), NewBookmark->Type() ) ); NewBookmark->SetPrevious ( NewBookmark->Value() ); AddBookmark ( NewBookmark ); AddBookmarkMap( NewBookmark ); } if ( m_vBookmarks.size() > 0 ) PopulateList(); } else { ASSERT ( " !Invalid Bookmark File..." ); MessageBox( nullptr, _T("Could not load properly. Invalid Bookmark file."), _T("Error"), MB_OK | MB_ICONERROR ); return; } } fclose( pFile ); } }
////////////////////////////////////////////////////////// // TMapDC // ------ // Initialize GDI pen cache void TMapDC::InitCacheData() { TRACE ("TMapDC::InitCacheData called"); if ( LastPens == NULL ) { LastPens = (TPenColor16 **)GetMemory (COLOR16_CACHE_SIZE * sizeof (TPenColor16 *)); for (int i = 0 ; i < COLOR16_CACHE_SIZE ; i++) { LastPens[i] = 0; } atexit (CleanupCacheData); } }
/* ============= Q3_CopyLump ============= */ int Q3_CopyLump( dheader_t *header, int lump, void **dest, int size ) { int length, ofs; length = header->lumps[lump].filelen; ofs = header->lumps[lump].fileofs; if ( length % size ) { Error ("Q3_LoadBSPFile: odd lump size"); } *dest = GetMemory(length); memcpy( *dest, (byte *)header + ofs, length ); return length / size; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== bspbrush_t *AllocBrush( int numsides ) { bspbrush_t *bb; int c; c = (int)&( ( (bspbrush_t *)0 )->sides[numsides] ); bb = GetMemory( c ); memset( bb, 0, c ); if ( numthreads == 1 ) { c_active_brushes++; c_brushmemory += MemorySize( bb ); if ( c_brushmemory > c_peak_brushmemory ) { c_peak_brushmemory = c_brushmemory; } } //end if return bb; } //end of the function AllocBrush
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AddThread( void ( *func )(int) ) { thread_t *thread; if ( numthreads == 1 ) { if ( currentnumthreads >= numthreads ) { return; } currentnumthreads++; func( -1 ); currentnumthreads--; } //end if else { ThreadLock(); if ( currentnumthreads >= numthreads ) { ThreadUnlock(); return; } //end if //allocate new thread thread = GetMemory( sizeof( thread_t ) ); if ( !thread ) { Error( "can't allocate memory for thread\n" ); } // thread->threadid = currentthreadid; if ( pthread_create( &thread->thread, attrib, (pthread_startroutine_t)func, (pthread_addr_t)thread->threadid ) == -1 ) { Error( "pthread_create failed" ); } //add the thread to the end of the list thread->next = NULL; if ( lastthread ) { lastthread->next = thread; } else { firstthread = thread;} lastthread = thread; // #ifdef THREAD_DEBUG qprintf( "added thread with id %d\n", thread->threadid ); #endif //THREAD_DEBUG // currentnumthreads++; currentthreadid++; // ThreadUnlock(); } //end else } //end of the function AddThread
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int BotInterpolateCharacters( int handle1, int handle2, int desiredskill ) { bot_character_t *ch1, *ch2, *out; int i, handle; float scale; ch1 = BotCharacterFromHandle( handle1 ); ch2 = BotCharacterFromHandle( handle2 ); if ( !ch1 || !ch2 ) { return 0; } //find a free spot for a character for ( handle = 1; handle <= MAX_CLIENTS; handle++ ) { if ( !botcharacters[handle] ) { break; } } //end for if ( handle > MAX_CLIENTS ) { return 0; } out = (bot_character_t *) GetClearedMemory( sizeof( bot_character_t ) + MAX_CHARACTERISTICS * sizeof( bot_characteristic_t ) ); out->skill = desiredskill; strcpy( out->filename, ch1->filename ); botcharacters[handle] = out; scale = (float) ( desiredskill - 1 ) / ( ch2->skill - ch1->skill ); for ( i = 0; i < MAX_CHARACTERISTICS; i++ ) { // if ( ch1->c[i].type == CT_FLOAT && ch2->c[i].type == CT_FLOAT ) { out->c[i].type = CT_FLOAT; out->c[i].value._float = ch1->c[i].value._float + ( ch2->c[i].value._float - ch1->c[i].value._float ) * scale; } //end if else if ( ch1->c[i].type == CT_INTEGER ) { out->c[i].type = CT_INTEGER; out->c[i].value.integer = ch1->c[i].value.integer; } //end else if else if ( ch1->c[i].type == CT_STRING ) { out->c[i].type = CT_STRING; out->c[i].value.string = (char *) GetMemory( strlen( ch1->c[i].value.string ) + 1 ); strcpy( out->c[i].value.string, ch1->c[i].value.string ); } //end else if } //end for return handle; } //end of the function BotInterpolateCharacters
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== bspbrush_t *AllocBrush (int numsides) { bspbrush_t *bb; size_t c; c = sizeof(*bb) + sizeof(*bb->sides) * numsides; bb = GetMemory(c); memset (bb, 0, c); if (numthreads == 1) { c_active_brushes++; c_brushmemory += MemorySize(bb); if (c_brushmemory > c_peak_brushmemory) c_peak_brushmemory = c_brushmemory; } //end if return bb; } //end of the function AllocBrush
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== libvar_t *LibVar(char *var_name, char *value) { libvar_t *v; v = LibVarGet(var_name); if (v) return v; //create new variable v = LibVarAlloc(var_name); //variable string v->string = (char *)GetMemory((unsigned long)strlen(value) + 1); strcpy(v->string, value); //the value v->value = LibVarStringValue(v->string); //variable is modified v->modified = qtrue; // return v; } //end of the function LibVar
/* ================= AddFunctionName ================= */ void AddFunctionName (char *funcname, char *filename, tokenList_t *head) { replacefunc_t *f; tokenList_t *list; if ( FindFunctionName(funcname) ) { return; } #if defined( __linux__ ) || defined( __FreeBSD__ ) // the bad thing is, this doesn't preprocess .. on __linux__ this // function is not implemented (q_math.c) if ( !Q_stricmp( funcname, "BoxOnPlaneSide" ) ) { return; } #endif // NERVE - SMF - workaround for Graeme's predifined MACOSX functions // TTimo - looks like linux version needs to escape those too #if defined( _WIN32 ) || defined( __linux__ ) || defined( __FreeBSD__ ) if ( !Q_stricmp(funcname, "qmax") ) { return; } else if ( !Q_stricmp(funcname, "qmin") ) { return; } #endif // -NERVE - SMF f = (replacefunc_t *) GetMemory( sizeof( replacefunc_t ) + strlen( funcname ) + 1 + 6 + strlen( filename ) + 1 ); f->name = (char *) f + sizeof( replacefunc_t ); strcpy( f->name, funcname ); f->newname = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1; sprintf( f->newname, "F%d", numfuncs++ ); f->filename = (char *) f + sizeof( replacefunc_t ) + strlen( funcname ) + 1 + strlen( f->newname ) + 1; strcpy( f->filename, filename ); f->next = replacefuncs; replacefuncs = f; // construct the declaration list = head; f->dec[0] = '\0'; ConcatDec( list, f->dec, 0 ); } //end of the function AddFunctionName
//获取文件内容 bool AnalyseClassCallRelation::GetFile(const string &strPath, char *&pOuter, unsigned char byMenID) { FILE *fp; fp = fopen(strPath.c_str(), "rb"); if ( ! fp) { return false; } fseek(fp, 0, SEEK_END); unsigned dwFileLen = ftell(fp); rewind(fp); char *pBuf = GetMemory(dwFileLen+1, byMenID); fread(pBuf, dwFileLen, 1, fp); fclose(fp); pBuf[dwFileLen] = 0; pOuter = pBuf; return true; }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void InitLevelItemHeap( void ) { int i, max_levelitems; if ( levelitemheap ) { FreeMemory( levelitemheap ); } max_levelitems = (int) LibVarValue( "max_levelitems", "256" ); levelitemheap = (levelitem_t *) GetMemory( max_levelitems * sizeof( levelitem_t ) ); for ( i = 0; i < max_levelitems - 2; i++ ) { levelitemheap[i].next = &levelitemheap[i + 1]; } //end for levelitemheap[max_levelitems - 1].next = NULL; // freelevelitems = levelitemheap; } //end of the function InitLevelItemHeap