• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ REALLOC函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __profile_call

void 
__profile_call(ADDR caller, ADDR callee, char *caller_name, char *callee_name)
{
#ifdef _DEBUG
  return;
#else
  if (num_counts == 0)
    ir_prof_start();

  if (num_counts == sizeof_counts_array) {
    sizeof_counts_array *= 2;
    counts_array = (counts_entry *)REALLOC(
		    counts_array, sizeof_counts_array);
    PR_ASSERT(counts_array, "realloc of counts_array failed");
  }

  hash_entry(caller, callee, caller_name, callee_name);
#endif
}
开发者ID:sharugupta,项目名称:OpenUH,代码行数:19,代码来源:ir_prof.c


示例2: pb_validate_add_buffer

enum pipe_error
pb_validate_add_buffer(struct pb_validate *vl,
                       struct pb_buffer *buf)
{
    assert(buf);
    if(!buf)
        return PIPE_ERROR;

    /* We only need to store one reference for each buffer, so avoid storing
     * consecutive references for the same buffer. It might not be the more
     * common pasttern, but it is easy to implement.
     */
    if(vl->used && vl->buffers[vl->used - 1] == buf) {
        return PIPE_OK;
    }

    /* Grow the table */
    if(vl->used == vl->size) {
        unsigned new_size;
        struct pb_buffer **new_buffers;

        new_size = vl->size * 2;
        if(!new_size)
            return PIPE_ERROR_OUT_OF_MEMORY;

        new_buffers = (struct pb_buffer **)REALLOC(vl->buffers,
        vl->size*sizeof(struct pb_buffer *),
        new_size*sizeof(struct pb_buffer *));
        if(!new_buffers)
            return PIPE_ERROR_OUT_OF_MEMORY;

        memset(new_buffers + vl->size, 0, (new_size - vl->size)*sizeof(struct pb_buffer *));

        vl->size = new_size;
        vl->buffers = new_buffers;
    }

    assert(!vl->buffers[vl->used]);
    pb_reference(&vl->buffers[vl->used], buf);
    ++vl->used;

    return PIPE_OK;
}
开发者ID:astrofimov,项目名称:vgallium,代码行数:43,代码来源:pb_validate.c


示例3: __gf_realloc

void *
__gf_realloc (void *ptr, size_t size)
{
        size_t          tot_size = 0;
        char            *orig_ptr = NULL;
        xlator_t        *xl = NULL;
        uint32_t        type = 0;
        char            *new_ptr;

        if (!THIS->ctx->mem_acct_enable)
                return REALLOC (ptr, size);

        REQUIRE(NULL != ptr);

        tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE;

        orig_ptr = (char *)ptr - 8 - 4;

        GF_ASSERT (*(uint32_t *)orig_ptr == GF_MEM_HEADER_MAGIC);

        orig_ptr = orig_ptr - sizeof(xlator_t *);
        xl = *((xlator_t **)orig_ptr);

        orig_ptr = (char *)ptr - GF_MEM_HEADER_SIZE;
        type = *(uint32_t *)orig_ptr;

        new_ptr = realloc (orig_ptr, tot_size);
        if (!new_ptr) {
                gf_log_nomem ("", GF_LOG_ALERT, tot_size);
                return NULL;
        }

        /*
         * We used to pass (char **)&ptr as the second
         * argument after the value of realloc was saved
         * in ptr, but the compiler warnings complained
         * about the casting to and forth from void ** to
         * char **.
         */
        gf_mem_set_acct_info (xl, &new_ptr, size, type);

        return (void *)new_ptr;
}
开发者ID:koordinates,项目名称:glusterfs,代码行数:43,代码来源:mem-pool.c


示例4: add_init_section

int add_init_section(InitFile *inif, InitSection *inis)
{
    int i;
    InitSection *oinis;
    if ((i = find_init_section(inif, inis->section_name)) >= 0) {
	oinis = inif->sections[i];
	inif->sections[i] = inis;
	free_init_section(oinis);
	return INIT_FILE_PRESENT;
    } 
    if (inif->num_sections == inif->size_sections) {
	inif->size_sections += 10;
	inif->sections = REALLOC(inif->sections, 
				 sizeof(InitSection *) * inif->size_sections);
    }
    inif->sections[inif->num_sections] = inis;
    ++(inif->num_sections);
    return INIT_FILE_NOT_PRESENT;
}
开发者ID:0x00evil,项目名称:otp,代码行数:19,代码来源:init_file.c


示例5: sStatment_new

sStatment* sStatment_new(sObject* block, int sline, char* sname)
{
    if(SBLOCK(block).mStatmentsNum >= SBLOCK(block).mStatmentsSize) {
        const int statments_size = SBLOCK(block).mStatmentsSize;

        int new_statments_size = SBLOCK(block).mStatmentsSize * 2;
        SBLOCK(block).mStatments = REALLOC(SBLOCK(block).mStatments, sizeof(sStatment)*new_statments_size);
        memset(SBLOCK(block).mStatments + SBLOCK(block).mStatmentsSize, 0, sizeof(sStatment)*(new_statments_size - SBLOCK(block).mStatmentsSize));
        SBLOCK(block).mStatmentsSize = new_statments_size;
    }

    sStatment* self = SBLOCK(block).mStatments + SBLOCK(block).mStatmentsNum;
    SBLOCK(block).mStatmentsNum++;
    self->mLine = sline;
    self->mFName = STRDUP(sname);
    self->mFlags = 0;

    return self;
}
开发者ID:ab25cq,项目名称:xyzsh,代码行数:19,代码来源:block.c


示例6: vlVaBufferSetNumElements

VAStatus
vlVaBufferSetNumElements(VADriverContextP ctx, VABufferID buf_id,
                         unsigned int num_elements)
{
   vlVaBuffer *buf;

   if (!ctx)
      return VA_STATUS_ERROR_INVALID_CONTEXT;

   buf = handle_table_get(VL_VA_DRIVER(ctx)->htab, buf_id);
   buf->data = REALLOC(buf->data, buf->size * buf->num_elements,
                       buf->size * num_elements);
   buf->num_elements = num_elements;

   if (!buf->data)
      return VA_STATUS_ERROR_ALLOCATION_FAILED;

   return VA_STATUS_SUCCESS;
}
开发者ID:juhapekka,项目名称:juha_mesaexperimentals,代码行数:19,代码来源:buffer.c


示例7: AddLine

void AddLine(int SkipLineInfo)
{
	if(/*ooutptr!=outptr&&*/dbgact==0&&(oline!=linenumber||omodule!=currentfileinfo)){
		while(ooutptr>outptr&&pdbg!=0&&ooutptr!=0xffffffff)KillLastLine();
		if(pdbg==pdbgmax){
			pdbgmax+=MAXDBGS;
			dbgloc=(unsigned int *)  REALLOC(dbgloc,pdbgmax*sizeof(unsigned int));
			dbgnum=(unsigned int *)  REALLOC(dbgnum,pdbgmax*sizeof(unsigned int));
			dbgmod=(unsigned short *)REALLOC(dbgmod,pdbgmax*sizeof(unsigned short));
			if(lstflag){
				lststring=(char **)REALLOC(lststring,pdbgmax*sizeof(char *));
				lstflag=(unsigned char *)REALLOC(lstflag,pdbgmax*sizeof(char));
				lstend=(unsigned int *)REALLOC(lstend,pdbgmax*sizeof(unsigned int));
				memset((char *)lstflag+(pdbgmax-MAXDBGS),-1,MAXDBGS*sizeof(char));
				memset((unsigned int *)lstend+(pdbgmax-MAXDBGS),0,MAXDBGS*sizeof(unsigned int));
			}
		}
		dbgloc[pdbg]=ooutptr=outptr;
		dbgnum[pdbg]=oline=linenumber;
		dbgmod[pdbg]=(unsigned short)currentfileinfo;
		omodule=currentfileinfo;
		if(dbg&2){
			if(SkipLineInfo)lststring[pdbg]=NULL;
			else{
				char *ofs=startline;
				char c;
				int sizestring=0;
				char buf[MAXLSTSTR];
				for(;sizestring<(MAXLSTSTR-1);sizestring++){
					c=*ofs;
					ofs=ofs+1;
					if(c==13||ofs==endinput)break;
					buf[sizestring]=c;
				}
				buf[sizestring]=0;
				strbtrim(buf);
				if((sizestring=strlen(buf))==0)lststring[pdbg]=NULL;
				else{
					lststring[pdbg]=(char *)MALLOC(sizestring+1);
					strcpy(lststring[pdbg],buf);
				}
			}
			lstflag[pdbg]=(unsigned char)(am32|lsttypedata);
			AddEndLine();
//		printf("%s(%d) outptr=%d\n",(startfileinfo+currentfileinfo)->filename,linenumber,outptr);
		}
		pdbg++;
		(startfileinfo+currentfileinfo)->numdline++;
	}
}
开发者ID:EmilHalim,项目名称:c--sphinx,代码行数:50,代码来源:DEBUG.CPP


示例8: oputs

void oputs ( int streamid, int detail, char *string )
{
     int i, j;

     if ( streamid == OUT_SYS && !quietmode )
     {
          printf ( string );
          fflush ( stdout );
     }

     if ( detail_level < detail )
          return;
     
     for ( i = 0; i < output_stream_count; ++i )
     {
          if ( streamid == streams[i].id )
          {
               if ( streams[i].valid )
               {
                    fputs ( string, streams[i].f );
                    if ( streams[i].autoflush )
                         fflush ( streams[i].f );
                    break;
               }
	       else
	       {
		    if ( streams[i].buffer )
		    {
			 j = strlen ( streams[i].buffer ) +
			      strlen ( string ) + 1;
			 streams[i].buffer = (char *)REALLOC ( streams[i].buffer, j );
			 strcat ( streams[i].buffer, string );
		    }
		    else
		    {
			 streams[i].buffer = (char *)MALLOC ( strlen ( string ) + 1 );
			 strcpy ( streams[i].buffer, string );
		    }
	       }
          }
     }
}
开发者ID:Quamber,项目名称:lil-gp-eclipse,代码行数:42,代码来源:output.c


示例9: TS_AddExtension

boolean TS_AddExtension(char ** ppszExtList, char * psz)
{
   char *   pExt;
   
   if (!ppszExtList || !psz)
      return FALSE;

   if (*ppszExtList)
      pExt = REALLOC(*ppszExtList, STRLEN(*ppszExtList) + STRLEN(psz) + STRLEN(MP_EXT_SEPARATOR) + 1);
   else
      pExt = MALLOC(STRLEN(psz) + STRLEN(MP_EXT_SEPARATOR) + 1);

   if (!pExt)
      return FALSE;

   STRCAT(pExt, psz);
   STRCAT(pExt, MP_EXT_SEPARATOR);
   *ppszExtList = pExt;
   return TRUE;
}
开发者ID:TopSoup,项目名称:navigate,代码行数:20,代码来源:wincontrol.c


示例10: AllocSet

static a_reduce_action *addReduceAction( a_pro *pro, a_word *follow, a_reduce_action *r )
{
    a_reduce_action *raction;
    a_reduce_action *new_raction;
    a_word *new_follow;
    size_t i;

    for( raction = r; raction->pro != NULL; ) {
        ++raction;
    }
    i = raction - r;
    new_follow = AllocSet( 1 );
    Assign( new_follow, follow );
    new_raction = REALLOC( r, i + 2, a_reduce_action );
    new_raction[i].pro = pro;
    new_raction[i].follow = new_follow;
    new_raction[i + 1].pro = NULL;
    new_raction[i + 1].follow = NULL;
    return( new_raction );
}
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:20,代码来源:elimunit.c


示例11: spif_str_trim

spif_bool_t
spif_str_trim(spif_str_t self)
{
    spif_charptr_t start, end;

    ASSERT_RVAL(!SPIF_STR_ISNULL(self), FALSE);
    start = self->s;
    end = self->s + self->len - 1;
    for (; isspace((spif_uchar_t) (*start)) && (start < end); start++);
    for (; isspace((spif_uchar_t) (*end)) && (start < end); end--);
    if (start > end) {
        return spif_str_done(self);
    }
    *(++end) = 0;
    self->len = (spif_stridx_t) (end - start);
    self->size = self->len + 1;
    memmove(self->s, start, self->size);
    self->s = (spif_charptr_t) REALLOC(self->s, self->size);
    return TRUE;
}
开发者ID:mej,项目名称:libast,代码行数:20,代码来源:str.c


示例12: expand_n_viterbi_egraphs

static void expand_n_viterbi_egraphs(int req_n_viterbi_egraph_size)
{
    int old_size,i;

    if (req_n_viterbi_egraph_size > max_n_viterbi_egraph_size) {
        old_size = max_n_viterbi_egraph_size;

        while (req_n_viterbi_egraph_size > max_n_viterbi_egraph_size) {
            max_n_viterbi_egraph_size *= 2;
        }

        n_viterbi_egraphs =
            (V_ENT_PTR *)REALLOC(n_viterbi_egraphs,
                                 max_n_viterbi_egraph_size * sizeof(V_ENT_PTR));

        for (i = old_size; i < max_n_viterbi_egraph_size; i++) {
            n_viterbi_egraphs[i] = NULL;
        }
    }
}
开发者ID:gokhansolak,项目名称:yap-6.3,代码行数:20,代码来源:viterbi.c


示例13: REALLOC

void *Clear_realloc(void *OldPtr,size_t OldSize,size_t NewSize)

{
void *NewPtr ;

NewPtr = REALLOC(OldPtr,NewSize) ;

if (!NewPtr)
  {
  printf("ERROR - No more memory\n") ;
/*  werror(E_OUT_OF_MEM,__FILE__,NewSize);*/
  exit (1);
  }

if (NewPtr)
  if (NewSize > OldSize)
    memset((char *) NewPtr + OldSize,0x00,NewSize - OldSize) ;

return NewPtr ;
}
开发者ID:FurCode,项目名称:gbdk-darwin,代码行数:20,代码来源:NewAlloc.c


示例14: add_completer_widget

static void add_completer_widget(Widget w, int row)
{
  if (row >= 0)
    {
      if (cmpwids_size <= row)
	{
	  int i;
	  i = cmpwids_size;
	  cmpwids_size = row + 8;
	  if (cmpwids == NULL)
	    cmpwids = (Widget *)CALLOC(cmpwids_size, sizeof(Widget));
	  else 
	    {
	      cmpwids = (Widget *)REALLOC(cmpwids, cmpwids_size * sizeof(Widget));
	      for (; i < cmpwids_size; i++) cmpwids[i] = NULL;
	    }
	}
      cmpwids[row] = w;
    }
}
开发者ID:huangjs,项目名称:cl,代码行数:20,代码来源:snd-xlistener.c


示例15: add_unique_range_nosort

void add_unique_range_nosort(
                            range_list_t *ranges, 
                            GElf_Off start, 
                            GElf_Off length, 
                            void *user,
                            void (*err_fn)(range_error_t, range_t *, range_t *),
                            void (*user_dtor)(void * )) 
{
    if (ranges->num_ranges == ranges->array_length) {
        ranges->array_length += PARALLEL_ARRAY_SIZE;
        ranges->array = REALLOC(ranges->array, 
                                ranges->array_length*sizeof(range_t));
    }
    ranges->array[ranges->num_ranges].start  = start;
    ranges->array[ranges->num_ranges].length = length;
    ranges->array[ranges->num_ranges].user   = user;
    ranges->array[ranges->num_ranges].err_fn = err_fn;
    ranges->array[ranges->num_ranges].user_dtor = user_dtor;
    ranges->num_ranges++;
}
开发者ID:2fast4u88,项目名称:oxygen_build,代码行数:20,代码来源:rangesort.c


示例16: tokens_expand

static void tokens_expand( struct ureg_tokens *tokens,
                           unsigned count )
{
   unsigned old_size = tokens->size * sizeof(unsigned);

   if (tokens->tokens == error_tokens) {
      return;
   }

   while (tokens->count + count > tokens->size) {
      tokens->size = (1 << ++tokens->order);
   }

   tokens->tokens = REALLOC(tokens->tokens, 
                            old_size,
                            tokens->size * sizeof(unsigned));
   if (tokens->tokens == NULL) {
      tokens_error(tokens);
   }
}
开发者ID:blckshrk,项目名称:Mesa,代码行数:20,代码来源:tgsi_ureg.c


示例17: PutEvent

BOOL
PutEvent (
    PINPUT_RECORD	InputRecord
    )
{

    EnterCriticalSection(&(EventBuffer.CriticalSection));

    //
    //	If no space at beginning of buffer, resize and shift right
    //
    if ( EventBuffer.EventIndex == 0 ) {

	EventBuffer.EventBuffer = REALLOC( EventBuffer.EventBuffer,
					   (EventBuffer.MaxEvents + EVENT_INCREMENT) * sizeof(INPUT_RECORD));

	if ( !EventBuffer.EventBuffer ) {
	    CleanExit(1, 0);
	}

	memmove( EventBuffer.EventBuffer + EVENT_INCREMENT,
		 EventBuffer.EventBuffer ,
		 EventBuffer.NumberOfEvents * sizeof(INPUT_RECORD) );

	EventBuffer.EventIndex = EVENT_INCREMENT;
    }

    //
    //	Add event
    //
    EventBuffer.EventIndex--;
    EventBuffer.NumberOfEvents++;

    memcpy( EventBuffer.EventBuffer + EventBuffer.EventIndex,
	    InputRecord,
	    sizeof(INPUT_RECORD ));

    LeaveCriticalSection(&(EventBuffer.CriticalSection));

    return TRUE;
}
开发者ID:mingpen,项目名称:OpenNT,代码行数:41,代码来源:console.c


示例18: util_bitmask_resize

/**
 * Resize the bitmask if necessary 
 */
static inline boolean
util_bitmask_resize(struct util_bitmask *bm,
                    unsigned minimum_index)
{
   unsigned minimum_size = minimum_index + 1;
   unsigned new_size;
   util_bitmask_word *new_words;

   /* Check integer overflow */
   if(!minimum_size)
      return FALSE;
      
   if(bm->size >= minimum_size)
      return TRUE;

   assert(bm->size % UTIL_BITMASK_BITS_PER_WORD == 0);
   new_size = bm->size;
   while(new_size < minimum_size) {
      new_size *= 2;
      /* Check integer overflow */
      if(new_size < bm->size)
         return FALSE;
   }
   assert(new_size);
   assert(new_size % UTIL_BITMASK_BITS_PER_WORD == 0);
   
   new_words = (util_bitmask_word *)REALLOC((void *)bm->words,
                                            bm->size / UTIL_BITMASK_BITS_PER_BYTE,
                                            new_size / UTIL_BITMASK_BITS_PER_BYTE);
   if (!new_words)
      return FALSE;
   
   memset(new_words + bm->size/UTIL_BITMASK_BITS_PER_WORD, 
          0, 
          (new_size - bm->size)/UTIL_BITMASK_BITS_PER_BYTE);
   
   bm->size = new_size;
   bm->words = new_words;
   
   return TRUE;
}
开发者ID:Distrotech,项目名称:Mesa,代码行数:44,代码来源:u_bitmask.c


示例19: sizeof

//
// Add the given value to the list of suggested values for this parameter 
//
bool ParameterDefinition::addValueOption(const char *value)
{
    int position;

    if (!this->valueOptions) {
	int size = 4;
	this->valueOptions = (char**)MALLOC(size * sizeof(char*));
	memset(this->valueOptions,0, size * sizeof(char*));
	position = 0;
    } else {
	position = 0;
	while (this->valueOptions[position])
	    position++;	
	int nextpos = position + 1;
	switch (nextpos) {
	    case 4:
	    case 8:
	    case 16:
	    case 32:
	    case 64:
		this->valueOptions = (char**)REALLOC((void*)this->valueOptions,
					2 * nextpos * sizeof(char*));
		memset(this->valueOptions + nextpos, 0, nextpos*sizeof(char*));
		break;
	    default:
		if (nextpos > 64) {
		    fprintf(stderr,
			"Too many value options for parameter (ignoring)");
		    position = -1;
		}
		break;
	}
    }
    if (position >= 0) {
	this->valueOptions[position] = DuplicateString(value);
	return true;
    } else {
	return false;
    }

}
开发者ID:BackupTheBerlios,项目名称:opendx2,代码行数:44,代码来源:ParameterDefinition.cpp


示例20: gges_mapping_append_symbol

void gges_mapping_append_symbol(struct gges_mapping *mapping, char *token)
{
    int tlen;

    if (mapping) {
        tlen = strlen(token);
        /* first, check to see if the string buffer needs
         * extending, and realloc as required */
        if ((mapping->l + tlen + 1) > mapping->sz) {
            while (mapping->sz < (mapping->l + tlen + 1)) mapping->sz += BUFFER_INC;

            mapping->buffer = REALLOC(mapping->buffer, mapping->sz, sizeof(char));
        }

        /* then, push terminal symbol into stream */
        strcat(mapping->buffer, token);
        mapping->l += tlen;
    } else {
        fprintf(stdout, "%s", token);
    }
}
开发者ID:grantdick,项目名称:libgges,代码行数:21,代码来源:individual.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ REALM_ASSERT函数代码示例发布时间:2022-05-30
下一篇:
C++ REAL函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap