本文整理汇总了C++中REALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ REALLOC函数的具体用法?C++ REALLOC怎么用?C++ REALLOC使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了REALLOC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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++;
}
}
示例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 );
}
}
}
}
}
示例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;
}
示例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 );
}
示例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;
}
示例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;
}
}
}
示例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 ;
}
示例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;
}
}
示例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++;
}