当前位置: 首页>>代码示例>>C++>>正文


C++ xMalloc函数代码示例

本文整理汇总了C++中xMalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ xMalloc函数的具体用法?C++ xMalloc怎么用?C++ xMalloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xMalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int 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,代码来源:test-xInsertRegionAfter.c

示例2: main

int 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,代码来源:test-xGetPageOfAddr.c

示例3: create

Void TComCUIcField::create( UInt uiNumPartition )
{
  m_pcIc     = ( TComIc* )xMalloc( TComIc, uiNumPartition );
  m_pcIcd    = ( TComIc* )xMalloc( TComIc, uiNumPartition );

  m_uiNumPartition = uiNumPartition;
}
开发者ID:xuguangxin,项目名称:hevc,代码行数:7,代码来源:TComICInfo.cpp

示例4: List_Push_Front

void 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,代码来源:List.c

示例5: Platform_getProcessEnv

char* 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,代码来源:Platform.c

示例6: main

int 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,代码来源:test-xIsStaticBin.c

示例7: String_readLine

char* 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,代码来源:StringUtils.c

示例8: Panel_new

Panel* 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,代码来源:Panel.c

示例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,代码来源:mio.c

示例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,代码来源:helper.c

示例11: fopen

char *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,代码来源:configuration.cpp

示例12: compileRegex

static 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,代码来源:lregex.c

示例13: cArgNewFromLineFile

extern 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,代码来源:options.c

示例14: cArgNewFromArgv

extern 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,代码来源:options.c

示例15: cArgNewFromString

extern 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,代码来源:options.c


注:本文中的xMalloc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。