这篇教程C++ xMalloc函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中xMalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ xMalloc函数的具体用法?C++ xMalloc怎么用?C++ xMalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了xMalloc函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mainint main() { xRegion region1 = xMalloc(sizeof(xRegionType)); __XMALLOC_ASSERT(region1->next == NULL); __XMALLOC_ASSERT(region1->prev == NULL); xRegion region2 = xMalloc(sizeof(xRegionType)); __XMALLOC_ASSERT(region2->next == NULL); __XMALLOC_ASSERT(region2->prev == NULL); xRegion region3 = xMalloc(sizeof(xRegionType)); __XMALLOC_ASSERT(region3->next == NULL); __XMALLOC_ASSERT(region3->prev == NULL); // inserts region1 after region2 xInsertRegionAfter(region1, region2); __XMALLOC_ASSERT(region2->next == region1); __XMALLOC_ASSERT(region1->prev == region2); // inserts region3 after region2 xInsertRegionAfter(region3, region2); __XMALLOC_ASSERT(region2->next == region3); __XMALLOC_ASSERT(region3->prev == region2); __XMALLOC_ASSERT(region1->prev == region3); __XMALLOC_ASSERT(region3->next == region1); xFree(region1); xFree(region2); xFree(region3); return 0;}
开发者ID:ederc,项目名称:xmalloc,代码行数:31,
示例2: mainint main() { int i = 1, j = 1; // allocate memory and check that they lie on the very same xPage void *pa; void *pb; while (i<1009) { void *addra = xMalloc(i); void *addrb = xMalloc(i); pa = xGetPageOfAddr(addra); pb = xGetPageOfAddr(addrb); __XMALLOC_ASSERT(pa == pb); xFreeBinAddr(addra); xFreeBinAddr(addrb); i++; } // allocate 5 big blocks in memory ( 1007 bytes ) // => the first 4 are on the same page, // the fifth has to be on a different one void *addr[5]; void *p[5]; for (i = 0; i <= 4; i++) { addr[i] = xMalloc(1007); p[i] = xGetPageOfAddr(addr[i]); } // those should all be on the same page for(i = 0; i < 3; i++) for(j = 1; j <=3; j++) __XMALLOC_ASSERT(p[i] = p[j]); // p[4] should be on a different page __XMALLOC_ASSERT(p[4] != p[0]); return 0;}
开发者ID:ederc,项目名称:xmalloc,代码行数:35,
示例3: createVoid TComCUIcField::create( UInt uiNumPartition ){ m_pcIc = ( TComIc* )xMalloc( TComIc, uiNumPartition ); m_pcIcd = ( TComIc* )xMalloc( TComIc, uiNumPartition ); m_uiNumPartition = uiNumPartition;}
开发者ID:xuguangxin,项目名称:hevc,代码行数:7,
示例4: List_Push_Frontvoid List_Push_Front(LIST *list, void *elem){ LIST_NODE *ptr = NULL; LIST_NODE *tmp = NULL; if( NULL == list || NULL == elem){ return; } ptr = list->head; tmp = xMalloc( sizeof(LIST_NODE )); if( NULL == tmp ){ return ; } tmp->element = xMalloc( list->elem_size ); if( NULL == tmp->element ){ xFree(tmp); return; } xMemCpy(tmp->element,elem,list->elem_size); if( NULL == ptr ){ list->head = tmp; tmp->next = NULL; tmp->prev = NULL; } else{ ptr->prev = tmp; tmp->next = ptr; list->head = tmp; tmp->prev = NULL; } list->size += 1;}
开发者ID:almondyoung,项目名称:srs.win,代码行数:33,
示例5: Platform_getProcessEnvchar* Platform_getProcessEnv(pid_t pid) { char* env = NULL; int argmax; size_t bufsz = sizeof(argmax); int mib[3]; mib[0] = CTL_KERN; mib[1] = KERN_ARGMAX; if (sysctl(mib, 2, &argmax, &bufsz, 0, 0) == 0) { char* buf = xMalloc(argmax); if (buf) { mib[0] = CTL_KERN; mib[1] = KERN_PROCARGS2; mib[2] = pid; size_t bufsz = argmax; if (sysctl(mib, 3, buf, &bufsz, 0, 0) == 0) { if (bufsz > sizeof(int)) { char *p = buf, *endp = buf + bufsz; int argc = *(int*)p; p += sizeof(int); // skip exe p = strchr(p, 0)+1; // skip padding while(!*p && p < endp) ++p; // skip argv for (; argc-- && p < endp; p = strrchr(p, 0)+1) ; // skip padding while(!*p && p < endp) ++p; size_t size = endp - p; env = xMalloc(size+2); memcpy(env, p, size); env[size] = 0; env[size+1] = 0; } } free(buf); } } return env;}
开发者ID:EliteTK,项目名称:htop,代码行数:50,
示例6: mainint main() { int i; // alloc small memory blocks from static bins for (i = 1; i < __XMALLOC_MAX_SMALL_BLOCK_SIZE; i++) { void *p = xMalloc(i); xBin bin = xGetBinOfAddr(p); __XMALLOC_ASSERT(xIsStaticBin(bin) == TRUE); xFree(p); } // alloc new bin, which is not from the static ones xBin newBin = xMalloc(sizeof(xBinType)); __XMALLOC_ASSERT(xIsStaticBin(newBin) == FALSE); return 0;}
开发者ID:ederc,项目名称:xmalloc,代码行数:15,
示例7: String_readLinechar* String_readLine(FILE* fd) { const int step = 1024; int bufSize = step; char* buffer = xMalloc(step + 1); char* at = buffer; for (;;) { char* ok = fgets(at, step + 1, fd); if (!ok) { free(buffer); return NULL; } char* newLine = strrchr(at, '/n'); if (newLine) { *newLine = '/0'; return buffer; } else { if (feof(fd)) { return buffer; } } bufSize += step; buffer = xRealloc(buffer, bufSize + 1); at = buffer + bufSize - step; }}
开发者ID:ElvenSpellmaker,项目名称:htop,代码行数:25,
示例8: Panel_newPanel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar) { Panel* this; this = xMalloc(sizeof(Panel)); Object_setClass(this, Class(Panel)); Panel_init(this, x, y, w, h, type, owner, fuBar); return this;}
开发者ID:520lly,项目名称:htop,代码行数:7,
示例9: xMalloc/** * mio_new_file_full: * @filename: Filename to open, passed as-is to @open_func as the first argument * @mode: Mode in which open the file, passed as-is to @open_func as the second * argument * @open_func: A function with the fopen() semantic to use to open the file * @close_func: A function with the fclose() semantic to close the file when * the #MIO object is destroyed, or %NULL not to close the #FILE * object * * Creates a new #MIO object working on a file, from a filename and an opening * function. See also mio_new_file(). * * This function is generally overkill and mio_new_file() should often be used * instead, but it allows to specify a custom function to open a file, as well * as a close function. The former is useful e.g. if you need to wrap fopen() * for some reason (like filename encoding conversion for example), and the * latter allows you both to match your custom open function and to choose * whether the underlying #FILE object should or not be closed when mio_free() * is called on the returned object. * * Free-function: mio_free() * * Returns: A new #MIO on success, or %NULL on failure. */MIO *mio_new_file_full (const char *filename, const char *mode, MIOFOpenFunc open_func, MIOFCloseFunc close_func){ MIO *mio; /* we need to create the MIO object first, because we may not be able to close * the opened file if the user passed NULL as the close function, which means * that everything must succeed if we've opened the file successfully */ mio = xMalloc (1, MIO); if (mio) { FILE *fp = open_func (filename, mode); if (! fp) { eFree (mio); mio = NULL; } else { mio->type = MIO_TYPE_FILE; mio->impl.file.fp = fp; mio->impl.file.close_func = close_func; mio->refcount = 1; mio->udata.d = NULL; mio->udata.f = NULL; } } return mio;}
开发者ID:Dev0Null,项目名称:ctags,代码行数:58,
示例10: strReplace/** * Replace all occurrences of the sub-string old in the string src * with the sub-string new. The method is case sensitive for the * sub-strings new and old. The string parameter src must be an * allocated string, not a character array. * @param pszHayStack An allocated string reference (e.g. &string) * @param pszSearch The old sub-string * @param pszReplace The new sub-string * @return pszHayStack where all occurrences of the old sub-string are * replaced with the new sub-string. * MUST FREE in caller side and MUST place pszReplace with some data. */char* strReplace(const char* pszSearch, const char* pszReplace, const char* pszHayStack){ char* tok = NULL; char* newstr = NULL; char* oldstr = NULL; char* head = NULL; /* if either pszSearch or pszReplace is NULL, duplicate string a let caller handle it */ if(pszSearch == NULL || pszReplace == NULL) return strdup(pszHayStack); newstr = strdup(pszHayStack); head = newstr; while((tok = strstr(head, pszSearch))) { oldstr = newstr; newstr = xMalloc(strlen(oldstr) - strlen(pszSearch) + strlen(pszReplace) + 1); /*failed to alloc mem, free old string and return NULL */ if(newstr == NULL) { FREE(oldstr); return NULL; } memcpy(newstr, oldstr, tok - oldstr); memcpy(newstr + (tok - oldstr), pszReplace, strlen(pszReplace)); memcpy(newstr + (tok - oldstr) + strlen(pszReplace), tok + strlen(pszSearch), strlen(oldstr) - strlen(pszSearch) - (tok - oldstr)); memset(newstr + strlen(oldstr) - strlen(pszSearch) + strlen(pszReplace) , 0, 1); /* move back head right after the last pszReplace */ head = newstr + (tok - oldstr) + strlen(pszReplace); FREE(oldstr); } return newstr;}
开发者ID:rockmetoo,项目名称:monitad,代码行数:45,
示例11: fopenchar *find_file (const char *filename){ /* Search for the file filename in standard install locations */ FILE *tmp=NULL; char *file; /* Current directory */ tmp = fopen(filename, "r"); if (tmp!=NULL) { fclose(tmp); return strdup (filename); } /* Install directory */ file = (char*)xMalloc(strlen(PKGDATADIR)+strlen(filename)+2); sprintf(file, "%s/%s", PKGDATADIR, filename); tmp = fopen(file, "r"); if (tmp!=NULL) { fclose(tmp); return file; } perror("open"); free(file); return NULL;}
开发者ID:crutchwalkfactory,项目名称:motocakerteam,代码行数:32,
示例12: compileRegexstatic regex_t* compileRegex (const char* const regexp, const char* const flags){ int cflags = REG_EXTENDED | REG_NEWLINE; regex_t *result = NULL; int errcode; int i; for (i = 0 ; flags != NULL && flags [i] != '/0' ; ++i) { switch ((int) flags [i]) { case 'b': cflags &= ~REG_EXTENDED; break; case 'e': cflags |= REG_EXTENDED; break; case 'i': cflags |= REG_ICASE; break; default: error (WARNING, "unknown regex flag: '%c'", *flags); break; } } result = xMalloc (1, regex_t); errcode = regcomp (result, regexp, cflags); if (errcode != 0) { char errmsg[256]; regerror (errcode, result, errmsg, 256); error (WARNING, "regcomp %s: %s", regexp, errmsg); regfree (result); eFree (result); result = NULL; } return result;}
开发者ID:0xeuclid,项目名称:vim_for_UEFI,代码行数:29,
示例13: cArgNewFromLineFileextern cookedArgs* cArgNewFromLineFile (FILE* const fp){ cookedArgs* const result = xMalloc (1, cookedArgs); memset (result, 0, sizeof (cookedArgs)); result->args = argNewFromLineFile (fp); cArgRead (result); return result;}
开发者ID:abderrahim,项目名称:anjuta,代码行数:8,
示例14: cArgNewFromArgvextern cookedArgs* cArgNewFromArgv (char* const* const argv){ cookedArgs* const result = xMalloc (1, cookedArgs); memset (result, 0, sizeof (cookedArgs)); result->args = argNewFromArgv (argv); cArgRead (result); return result;}
开发者ID:abderrahim,项目名称:anjuta,代码行数:8,
示例15: cArgNewFromStringextern cookedArgs* cArgNewFromString (const char* string){ cookedArgs* const result = xMalloc (1, cookedArgs); memset (result, 0, sizeof (cookedArgs)); result->args = argNewFromString (string); cArgRead (result); return result;}
开发者ID:abderrahim,项目名称:anjuta,代码行数:8,
示例16: IOCP_AllocContextIOCP_CONTEXT* IOCP_AllocContext(IOCP* iocp){ IOCP_CONTEXT* context = NULL; context = xMalloc(sizeof(IOCP_CONTEXT)); xMemSet(context, 0, sizeof(IOCP_CONTEXT)); context->instPtr = iocp; return context;}
开发者ID:almondyoung,项目名称:srs.win,代码行数:8,
示例17: xMallocextern stringList *stringListNew (void){ stringList* const result = xMalloc (1, stringList); result->max = 0; result->count = 0; result->list = NULL; return result;}
开发者ID:b4n,项目名称:fishman-ctags,代码行数:8,
示例18: String_catchar* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); char* out = xMalloc(l1 + l2 + 1); strncpy(out, s1, l1); strncpy(out+l1, s2, l2+1); return out;}
开发者ID:ElvenSpellmaker,项目名称:htop,代码行数:8,
示例19: xMallocextern ptrArray *ptrArrayNew (ptrArrayDeleteFunc deleteFunc){ ptrArray* const result = xMalloc (1, ptrArray); result->max = 8; result->count = 0; result->array = xMalloc (result->max, void*); result->deleteFunc = deleteFunc; return result;}
开发者ID:StefanOberhumer,项目名称:geany,代码行数:9,
示例20: fileKindNewstatic kindOption* fileKindNew (char letter){ kindOption *fileKind; fileKind = xMalloc (1, kindOption); *(fileKind) = defaultFileKind; fileKind->letter = letter; return fileKind;}
开发者ID:relaxdiego,项目名称:ctags,代码行数:9,
示例21: trashPutstatic Trash* trashPut (Trash* trash, void* item, TrashDestroyItemProc destrctor){ Trash* t = xMalloc (1, Trash); t->next = trash; t->item = item; t->destrctor = destrctor? destrctor: eFree; return t;}
开发者ID:Monits,项目名称:ctags,代码行数:9,
示例22: List_NewLIST* List_New(unsigned int elem_size){ LIST* list = NULL; list = xMalloc(sizeof(LIST)); if( NULL == list){ return NULL; } list->size = 0; list->elem_size = elem_size; list->head = xMalloc(sizeof(LIST_NODE*)); if( NULL == list->head ){ xFree((list)); return NULL; } return list;}
开发者ID:almondyoung,项目名称:srs.win,代码行数:18,
示例23: xMallocstatic tokenInfo *copyToken (tokenInfo *other){ tokenInfo *const token = xMalloc (1, tokenInfo); token->type = other->type; token->keyword = other->keyword; token->string = vStringNewCopy (other->string); token->lineNumber = other->lineNumber; token->filePosition = other->filePosition; return token;}
开发者ID:Dev0Null,项目名称:ctags,代码行数:10,
示例24: HashCreateAllocHash * HashCreateAlloc(char copyKey, void *(*xMalloc)(size_t), void (*xFree)(void *)) { Hash * pHash = (Hash*)xMalloc(sizeof(Hash)); if (pHash != NULL) { HashInit(pHash, copyKey, xMalloc, xFree); return pHash; } else { return 0; }}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:10,
示例25: xMallocstatic tokenInfo *newToken (void){ tokenInfo *const token = xMalloc (1, tokenInfo); token->type = TOKEN_UNDEFINED; token->keyword = KEYWORD_NONE; token->string = vStringNew (); return token;}
开发者ID:neil-yi,项目名称:ffsource,代码行数:10,
示例26: List_Insertvoid List_Insert(LIST *list,void *elem, unsigned int index){ unsigned int counter = 0; LIST_NODE *ptr = NULL; LIST_NODE *ptr2 = NULL; LIST_NODE *tmp = NULL; if( NULL == list || NULL == elem ){ return ; } ptr = list->head; while( ptr != NULL && counter < index ){ ptr2 = ptr; ptr = ptr->next; counter ++; } ptr = ptr2; tmp = xMalloc( sizeof(LIST_NODE )); tmp->element = xMalloc( list->elem_size ); xMemCpy(tmp->element,elem,list->elem_size); if( list->head == ptr ){ ptr->prev = tmp; tmp->next = ptr; list->head = tmp; tmp->prev = NULL; } else if( NULL == ptr->next ){ ptr->next = tmp; tmp->prev = ptr; tmp->next = NULL; } else{ tmp->prev = ptr->prev; tmp->next = ptr; tmp->prev->next = tmp; ptr->prev = tmp; } list->size += 1;}
开发者ID:almondyoung,项目名称:srs.win,代码行数:43,
示例27: TraceScreen_newTraceScreen* TraceScreen_new(Process* process) { TraceScreen* this = xMalloc(sizeof(TraceScreen)); Object_setClass(this, Class(TraceScreen)); this->tracing = true; this->contLine = false; this->follow = false; FunctionBar* fuBar = FunctionBar_new(TraceScreenFunctions, TraceScreenKeys, TraceScreenEvents); CRT_disableDelay(); return (TraceScreen*) InfoScreen_init(&this->super, process, fuBar, LINES-2, "");}
开发者ID:wangkang007,项目名称:htop,代码行数:10,
示例28: List_Createint List_Create(LIST **list,unsigned int elem_size){ if( NULL == list){ return -1; } (*list) = xMalloc( sizeof(LIST) ); if( NULL == (*list)){ return -1; } (*list)->size = 0; (*list)->elem_size = elem_size; (*list)->head = xMalloc(sizeof(LIST_NODE*) ); if( NULL == (*list)->head ){ xFree((*list)); return -1; } return 0;}
开发者ID:almondyoung,项目名称:srs.win,代码行数:21,
注:本文中的xMalloc函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ xPortGetFreeHeapSize函数代码示例 C++ xIsCreateTaskStillRunning函数代码示例 |