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


C++ repalloc函数代码示例

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


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

示例1: ResourceOwnerEnlargePreparedStmts

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * prepared statements reference array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 */
void
ResourceOwnerEnlargePreparedStmts(ResourceOwner owner)
{
	int			newmax;

	if (owner->nstmts < owner->maxstmts)
		return;					/* nothing to do */

	if (owner->stmts == NULL)
	{
		newmax = 16;
		owner->stmts = (char *)
			MemoryContextAlloc(TopMemoryContext, newmax * CNAME_MAXLEN);
		owner->maxstmts = newmax;
	}
	else
	{
		newmax = owner->maxstmts * 2;
		owner->stmts = (char *)
			repalloc(owner->stmts, newmax * CNAME_MAXLEN);
		owner->maxstmts = newmax;
	}
}
开发者ID:techdragon,项目名称:Postgres-XL,代码行数:30,代码来源:resowner.c

示例2: ResourceOwnerEnlargeTupleDescs

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * tupdesc reference array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 */
void
ResourceOwnerEnlargeTupleDescs(ResourceOwner owner)
{
    int			newmax;

    if (owner->ntupdescs < owner->maxtupdescs)
        return;					/* nothing to do */

    if (owner->tupdescs == NULL)
    {
        newmax = 16;
        owner->tupdescs = (TupleDesc *)
                          MemoryContextAlloc(TopMemoryContext, newmax * sizeof(TupleDesc));
        owner->maxtupdescs = newmax;
    }
    else
    {
        newmax = owner->maxtupdescs * 2;
        owner->tupdescs = (TupleDesc *)
                          repalloc(owner->tupdescs, newmax * sizeof(TupleDesc));
        owner->maxtupdescs = newmax;
    }
}
开发者ID:leckie711,项目名称:incubator-hawq,代码行数:30,代码来源:resowner.c

示例3: ResourceOwnerEnlargeCatCacheListRefs

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * catcache-list reference array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 */
void
ResourceOwnerEnlargeCatCacheListRefs(ResourceOwner owner)
{
    int			newmax;

    if (owner->ncatlistrefs < owner->maxcatlistrefs)
        return;					/* nothing to do */

    if (owner->catlistrefs == NULL)
    {
        newmax = 16;
        owner->catlistrefs = (CatCList **)
                             MemoryContextAlloc(TopMemoryContext, newmax * sizeof(CatCList *));
        owner->maxcatlistrefs = newmax;
    }
    else
    {
        newmax = owner->maxcatlistrefs * 2;
        owner->catlistrefs = (CatCList **)
                             repalloc(owner->catlistrefs, newmax * sizeof(CatCList *));
        owner->maxcatlistrefs = newmax;
    }
}
开发者ID:leckie711,项目名称:incubator-hawq,代码行数:30,代码来源:resowner.c

示例4: ResourceOwnerEnlargeRelationRefs

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * relcache reference array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 */
void
ResourceOwnerEnlargeRelationRefs(ResourceOwner owner)
{
    int			newmax;

    if (owner->nrelrefs < owner->maxrelrefs)
        return;					/* nothing to do */

    if (owner->relrefs == NULL)
    {
        newmax = 16;
        owner->relrefs = (Relation *)
                         MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Relation));
        owner->maxrelrefs = newmax;
    }
    else
    {
        newmax = owner->maxrelrefs * 2;
        owner->relrefs = (Relation *)
                         repalloc(owner->relrefs, newmax * sizeof(Relation));
        owner->maxrelrefs = newmax;
    }
}
开发者ID:leckie711,项目名称:incubator-hawq,代码行数:30,代码来源:resowner.c

示例5: ResourceOwnerEnlargeFiles

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * files reference array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 */
void
ResourceOwnerEnlargeFiles(ResourceOwner owner)
{
	int			newmax;

	if (owner->nfiles < owner->maxfiles)
		return;					/* nothing to do */

	if (owner->files == NULL)
	{
		newmax = 16;
		owner->files = (File *)
			MemoryContextAlloc(TopMemoryContext, newmax * sizeof(File));
		owner->maxfiles = newmax;
	}
	else
	{
		newmax = owner->maxfiles * 2;
		owner->files = (File *)
			repalloc(owner->files, newmax * sizeof(File));
		owner->maxfiles = newmax;
	}
}
开发者ID:KMU-embedded,项目名称:mosbench-ext,代码行数:30,代码来源:resowner.c

示例6: ResourceOwnerEnlargePlanCacheRefs

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * plancache reference array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 */
void
ResourceOwnerEnlargePlanCacheRefs(ResourceOwner owner)
{
	int			newmax;

	if (owner->nplanrefs < owner->maxplanrefs)
		return;					/* nothing to do */

	if (owner->planrefs == NULL)
	{
		newmax = 16;
		owner->planrefs = (CachedPlan **)
			MemoryContextAlloc(TopMemoryContext, newmax * sizeof(CachedPlan *));
		owner->maxplanrefs = newmax;
	}
	else
	{
		newmax = owner->maxplanrefs * 2;
		owner->planrefs = (CachedPlan **)
			repalloc(owner->planrefs, newmax * sizeof(CachedPlan *));
		owner->maxplanrefs = newmax;
	}
}
开发者ID:KMU-embedded,项目名称:mosbench-ext,代码行数:30,代码来源:resowner.c

示例7: ResourceOwnerEnlargeSnapshots

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * snapshot reference array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 */
void
ResourceOwnerEnlargeSnapshots(ResourceOwner owner)
{
	int			newmax;

	if (owner->nsnapshots < owner->maxsnapshots)
		return;					/* nothing to do */

	if (owner->snapshots == NULL)
	{
		newmax = 16;
		owner->snapshots = (Snapshot *)
			MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Snapshot));
		owner->maxsnapshots = newmax;
	}
	else
	{
		newmax = owner->maxsnapshots * 2;
		owner->snapshots = (Snapshot *)
			repalloc(owner->snapshots, newmax * sizeof(Snapshot));
		owner->maxsnapshots = newmax;
	}
}
开发者ID:techdragon,项目名称:Postgres-XL,代码行数:30,代码来源:resowner.c

示例8: finalizeForecastModel

/*
 * finalizeForecastModel
 *
 * no more input tuples to read
 */
void 
finalizeForecastModel(ModelInfo *model)
{
	int length = 0;

	FunctionCall1(&(model->algInfo->algFinalizeForecastModel),PointerGetDatum(model->model));

	length = model->model->trainingTupleCount;

	//MEASURE-CHANGE
//	length=20;

	if (model->upperBound==0) {
		if(((int)(length*0.1))<1)
			model->lowerBound = 1;
		else
			model->lowerBound = (((int)(length*0.1)));
		//XXX: CHANGE FOR MESURING

		if(!model->errorArray){
			if(((int)(length*0.1))<2)
				model->errorArray = palloc0(2*sizeof(double));
			else
				model->errorArray = palloc0(((int)(length*0.1))*sizeof(double));
		}
		else
			if(model->upperBound < ((int)(length*0.1))){
				model->errorArray = repalloc(model->errorArray, ((int)(length*0.1))*sizeof(double));
				model->errorArray[((int)(length*0.1))-1] = 0.0;
			}

		if(((int)(length*0.1))<2)
			model->upperBound = 2;
		else
			model->upperBound = ((int)(length*0.1));
	}
}
开发者ID:Khalefa,项目名称:Miracle,代码行数:42,代码来源:algorithm.c

示例9: istore_pairs_insert

/*
 * insert key value to IStorePairs
 */
void
istore_pairs_insert(IStorePairs *pairs, int32 key, int32 val)
{
    if (pairs->size == pairs->used)
    {
        if (pairs->used == PAIRS_MAX(IStorePair))
            elog(ERROR, "istore can't have more than %lu keys", PAIRS_MAX(IStorePair));

        pairs->size *= 2;
        // overflow check pairs->size should have been grown but not exceed PAIRS_MAX(IStorePair)
        if (pairs->size < pairs->used || pairs->size > PAIRS_MAX(IStorePair))
            pairs->size = PAIRS_MAX(IStorePair);

        pairs->pairs = repalloc(pairs->pairs, pairs->size * sizeof(IStorePair));
    }

    pairs->pairs[pairs->used].key = key;
    pairs->pairs[pairs->used].val = val;
    pairs->buflen += digits32(key) + digits32(val) + BUFLEN_OFFSET;

    if (pairs->buflen < 0)
        elog(ERROR, "istore buffer overflow");
    pairs->used++;
}
开发者ID:adjust,项目名称:istore,代码行数:27,代码来源:pairs.c

示例10: ginInsertData

/*
 * Stores heap item pointer. For robust, it checks that
 * item pointer are ordered
 */
static void
ginInsertData(BuildAccumulator *accum, EntryAccumulator *entry, ItemPointer heapptr)
{
	if (entry->number >= entry->length)
	{
		accum->allocatedMemory += sizeof(ItemPointerData) * entry->length;
		entry->length *= 2;
		entry->list = (ItemPointerData *) repalloc(entry->list,
									sizeof(ItemPointerData) * entry->length);
	}

	if (entry->shouldSort == FALSE)
	{
		int			res = compareItemPointers(entry->list + entry->number - 1, heapptr);

		Assert(res != 0);

		if (res > 0)
			entry->shouldSort = TRUE;
	}

	entry->list[entry->number] = *heapptr;
	entry->number++;
}
开发者ID:qiuyesuifeng,项目名称:gpdb,代码行数:28,代码来源:ginbulk.c

示例11: add_gin_entry

/* Add new entry to GinEntries */
static int
add_gin_entry(GinEntries *entries, Datum entry)
{
	int			id = entries->count;

	if (entries->count >= entries->allocated)
	{
		if (entries->allocated)
		{
			entries->allocated *= 2;
			entries->buf = repalloc(entries->buf,
									sizeof(Datum) * entries->allocated);
		}
		else
		{
			entries->allocated = 8;
			entries->buf = palloc(sizeof(Datum) * entries->allocated);
		}
	}

	entries->buf[entries->count++] = entry;

	return id;
}
开发者ID:davidfetter,项目名称:postgresql_projects,代码行数:25,代码来源:jsonb_gin.c

示例12: MakeSharedInvalidMessagesArray

/*
 * Collect invalidation messages into SharedInvalidMessagesArray array.
 */
static void
MakeSharedInvalidMessagesArray(const SharedInvalidationMessage *msgs, int n)
{
	/*
	 * Initialise array first time through in each commit
	 */
	if (SharedInvalidMessagesArray == NULL)
	{
		maxSharedInvalidMessagesArray = FIRSTCHUNKSIZE;
		numSharedInvalidMessagesArray = 0;

		/*
		 * Although this is being palloc'd we don't actually free it directly.
		 * We're so close to EOXact that we now we're going to lose it anyhow.
		 */
		SharedInvalidMessagesArray = palloc(maxSharedInvalidMessagesArray
										* sizeof(SharedInvalidationMessage));
	}

	if ((numSharedInvalidMessagesArray + n) > maxSharedInvalidMessagesArray)
	{
		while ((numSharedInvalidMessagesArray + n) > maxSharedInvalidMessagesArray)
			maxSharedInvalidMessagesArray *= 2;

		SharedInvalidMessagesArray = repalloc(SharedInvalidMessagesArray,
											  maxSharedInvalidMessagesArray
										* sizeof(SharedInvalidationMessage));
	}

	/*
	 * Append the next chunk onto the array
	 */
	memcpy(SharedInvalidMessagesArray + numSharedInvalidMessagesArray,
		   msgs, n * sizeof(SharedInvalidationMessage));
	numSharedInvalidMessagesArray += n;
}
开发者ID:AXLEproject,项目名称:postgres,代码行数:39,代码来源:inval.c

示例13: ResourceOwnerEnlargeDSMs

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * dynamic shmem segment reference array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 */
void
ResourceOwnerEnlargeDSMs(ResourceOwner owner)
{
	int			newmax;

	if (owner->ndsms < owner->maxdsms)
		return;					/* nothing to do */

	if (owner->dsms == NULL)
	{
		newmax = 16;
		owner->dsms = (dsm_segment **)
			MemoryContextAlloc(TopMemoryContext,
							   newmax * sizeof(dsm_segment *));
		owner->maxdsms = newmax;
	}
	else
	{
		newmax = owner->maxdsms * 2;
		owner->dsms = (dsm_segment **)
			repalloc(owner->dsms, newmax * sizeof(dsm_segment *));
		owner->maxdsms = newmax;
	}
}
开发者ID:42penguins,项目名称:postgres,代码行数:31,代码来源:resowner.c

示例14: ResourceOwnerEnlargeBuffers

/*
 * Make sure there is room for at least one more entry in a ResourceOwner's
 * buffer array.
 *
 * This is separate from actually inserting an entry because if we run out
 * of memory, it's critical to do so *before* acquiring the resource.
 *
 * We allow the case owner == NULL because the bufmgr is sometimes invoked
 * outside any transaction (for example, during WAL recovery).
 */
void
ResourceOwnerEnlargeBuffers(ResourceOwner owner)
{
	int			newmax;

	if (owner == NULL ||
		owner->nbuffers < owner->maxbuffers)
		return;					/* nothing to do */

	if (owner->buffers == NULL)
	{
		newmax = 16;
		owner->buffers = (Buffer *)
			MemoryContextAlloc(TopMemoryContext, newmax * sizeof(Buffer));
		owner->maxbuffers = newmax;
	}
	else
	{
		newmax = owner->maxbuffers * 2;
		owner->buffers = (Buffer *)
			repalloc(owner->buffers, newmax * sizeof(Buffer));
		owner->maxbuffers = newmax;
	}
}
开发者ID:lhcezar,项目名称:postgres,代码行数:34,代码来源:resowner.c

示例15: pgss_shmem_startup


//.........这里部分代码省略.........
	memset(&info, 0, sizeof(info));
	info.keysize = sizeof(pgssHashKey);
	info.entrysize = offsetof(pgssEntry, query) +query_size;
	info.hash = pgss_hash_fn;
	info.match = pgss_match_fn;
	pgss_hash = ShmemInitHash("pg_stat_statements hash",
							  pgss_max, pgss_max,
							  &info,
							  HASH_ELEM | HASH_FUNCTION | HASH_COMPARE);

	LWLockRelease(AddinShmemInitLock);

	/*
	 * If we're in the postmaster (or a standalone backend...), set up a shmem
	 * exit hook to dump the statistics to disk.
	 */
	if (!IsUnderPostmaster)
		on_shmem_exit(pgss_shmem_shutdown, (Datum) 0);

	/*
	 * Attempt to load old statistics from the dump file, if this is the first
	 * time through and we weren't told not to.
	 */
	if (found || !pgss_save)
		return;

	/*
	 * Note: we don't bother with locks here, because there should be no other
	 * processes running when this code is reached.
	 */
	file = AllocateFile(PGSS_DUMP_FILE, PG_BINARY_R);
	if (file == NULL)
	{
		if (errno == ENOENT)
			return;				/* ignore not-found error */
		goto error;
	}

	buffer_size = query_size;
	buffer = (char *) palloc(buffer_size);

	if (fread(&header, sizeof(uint32), 1, file) != 1 ||
		header != PGSS_FILE_HEADER ||
		fread(&num, sizeof(int32), 1, file) != 1)
		goto error;

	for (i = 0; i < num; i++)
	{
		pgssEntry	temp;
		pgssEntry  *entry;

		if (fread(&temp, offsetof(pgssEntry, mutex), 1, file) != 1)
			goto error;

		/* Encoding is the only field we can easily sanity-check */
		if (!PG_VALID_BE_ENCODING(temp.key.encoding))
			goto error;

		/* Previous incarnation might have had a larger query_size */
		if (temp.key.query_len >= buffer_size)
		{
			buffer = (char *) repalloc(buffer, temp.key.query_len + 1);
			buffer_size = temp.key.query_len + 1;
		}

		if (fread(buffer, 1, temp.key.query_len, file) != temp.key.query_len)
			goto error;
		buffer[temp.key.query_len] = '\0';

		/* Clip to available length if needed */
		if (temp.key.query_len >= query_size)
			temp.key.query_len = pg_encoding_mbcliplen(temp.key.encoding,
													   buffer,
													   temp.key.query_len,
													   query_size - 1);
		temp.key.query_ptr = buffer;

		/* make the hashtable entry (discards old entries if too many) */
		entry = entry_alloc(&temp.key);

		/* copy in the actual stats */
		entry->counters = temp.counters;
	}

	pfree(buffer);
	FreeFile(file);
	return;

error:
	ereport(LOG,
			(errcode_for_file_access(),
			 errmsg("could not read pg_stat_statement file \"%s\": %m",
					PGSS_DUMP_FILE)));
	if (buffer)
		pfree(buffer);
	if (file)
		FreeFile(file);
	/* If possible, throw away the bogus file; ignore any error */
	unlink(PGSS_DUMP_FILE);
}
开发者ID:HBPSP8Repo,项目名称:NoDB,代码行数:101,代码来源:pg_stat_statements.c


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