本文整理汇总了C++中Realloc函数的典型用法代码示例。如果您正苦于以下问题:C++ Realloc函数的具体用法?C++ Realloc怎么用?C++ Realloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Realloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Write
DWORD TinyMemoryFile::Write(const void* pData, DWORD cbData)
{
if (pData == NULL || cbData == 0)
return FALSE;
if ((m_dwPosition + cbData) < m_dwPosition)
return FALSE;
//超出当前缓冲区大小重新分配大小
if ((m_dwPosition + cbData) > m_dwBufferSize)
{
if (!Realloc((m_dwPosition + cbData)))
return FALSE;
}
memcpy_s((BYTE*)pData + m_dwPosition, cbData, (BYTE*)pData, cbData);
m_dwPosition += cbData;
if (m_dwPosition > m_dwBufferSize)
m_dwBufferSize = m_dwPosition;
return cbData;
}
开发者ID:91yuan,项目名称:TinyUI,代码行数:20,代码来源:TinyIO.cpp
示例2: ipstr_list_parse
int ipstr_list_parse(const char* ipstr_list, struct in_addr** ip_list)
{
int count;
for (ip_list=NULL, count=0; ipstr_list; count++) {
struct in_addr a;
if (inet_aton(ipstr_list, &a) == -1) break;
*ip_list = Realloc(*ip_list, (count+1) * sizeof(struct in_addr));
if (!ip_list) {
return -1;
}
(*ip_list)[count] = a;
ipstr_list = strchr(ipstr_list, ':');
if (ipstr_list) ipstr_list++;
}
return count;
}
开发者ID:tridge,项目名称:junkcode,代码行数:20,代码来源:parseaddr.c
示例3: prs_set_buffer_size
BOOL prs_set_buffer_size(prs_struct *ps, uint32 newsize)
{
if (newsize > ps->buffer_size)
return prs_force_grow(ps, newsize - ps->buffer_size);
if (newsize < ps->buffer_size) {
char *new_data_p = Realloc(ps->data_p, newsize);
/* if newsize is zero, Realloc acts like free() & returns NULL*/
if (new_data_p == NULL && newsize != 0) {
DEBUG(0,("prs_set_buffer_size: Realloc failure for size %u.\n",
(unsigned int)newsize));
DEBUG(0,("prs_set_buffer_size: Reason %s\n",strerror(errno)));
return False;
}
ps->data_p = new_data_p;
ps->buffer_size = newsize;
}
return True;
}
开发者ID:Nymphetaminer,项目名称:dsl-n55u,代码行数:20,代码来源:parse_prs.c
示例4: Load
int MemoryBuffer::Load(const void *buf, __MEMBUF_INT__ bytes)
// Load this object with a unique copy of the specified buffer.
// Returns true if successful or false if an error occurs.
{
if(!mptr) { // Ensure that this buffer has been initialized
if(!Alloc(bytes)) return 0;
}
if(d_length < bytes) { // Ensure enough byte have been allocated
if(!Realloc(bytes, 0, 0)) return 0;
}
else { // Reuse the current memory segment
l_length = bytes;
}
// PC-lint 09/14/2005: Possible use of null pointer
if(!mptr) return 0;
memmove(mptr, (unsigned char *)buf, l_length);
return 1;
}
开发者ID:datareel,项目名称:datareel_4_visual_studio,代码行数:21,代码来源:membuf.cpp
示例5: Realloc
TString::TString( const char* c, unsigned int len )
{
data = NULL;
if( len==0 ) {
data = NULL;
length = 0;
}
else {
Realloc( len );
if( c ) {
char *copied = (char*) memccpy( data, c, 0, len );
if( copied ) {
copied--;
memset( copied, ' ', len - ( copied - data ) );
}
}
else
memset( data, ' ', len );
data[len] = 0;
}
}
开发者ID:Sustak,项目名称:final.utils,代码行数:21,代码来源:str.cpp
示例6: sizeof
int CLightmapManager::Load (int nLevel)
{
CFile cf;
tLightmapDataHeader ldh;
int i, bOk;
char szFilename [FILENAME_LEN];
CSegFace *faceP;
if (!(gameStates.app.bCacheLightmaps))
return 0;
if (!cf.Open (Filename (szFilename, nLevel), gameFolders.szCacheDir, "rb", 0))
return 0;
bOk = (cf.Read (&ldh, sizeof (ldh), 1) == 1);
if (bOk)
bOk = (ldh.nVersion == LIGHTMAP_DATA_VERSION) &&
(ldh.nCheckSum == CalcSegmentCheckSum ()) &&
(ldh.nSegments == gameData.segs.nSegments) &&
(ldh.nVertices == gameData.segs.nVertices) &&
(ldh.nFaces == gameData.segs.nFaces) &&
(ldh.nLights == m_list.nLights) &&
(ldh.nMaxLightRange == MAX_LIGHT_RANGE);
if (bOk) {
for (i = ldh.nFaces, faceP = FACES.faces.Buffer (); i; i--, faceP++) {
bOk = cf.Read (&faceP->nLightmap, sizeof (faceP->nLightmap), 1) == 1;
if (!bOk)
break;
}
}
if (bOk) {
for (i = 0; i < ldh.nBuffers; i++) {
bOk = cf.Read (m_list.buffers [i].bmP, sizeof (m_list.buffers [i].bmP), 1) == 1;
if (!bOk)
break;
}
}
if (bOk)
Realloc (ldh.nBuffers);
cf.Close ();
return bOk;
}
开发者ID:paud,项目名称:d2x-xl,代码行数:40,代码来源:lightmap.cpp
示例7: while
SEC_ACL *build_acl(struct ace_entry *ace_list)
{
SEC_ACE *aces = NULL;
SEC_ACL *result;
int num_aces = 0;
if (ace_list == NULL) return NULL;
/* Create aces */
while(ace_list->sid) {
SEC_ACCESS sa;
struct dom_sid sid;
/* Create memory for new ACE */
if (!(aces = Realloc(aces,
sizeof(SEC_ACE) * (num_aces + 1)))) {
return NULL;
}
/* Create ace */
init_sec_access(&sa, ace_list->mask);
char_to_sid(&sid, ace_list->sid);
init_sec_ace(&aces[num_aces], &sid, ace_list->type,
sa, ace_list->flags);
num_aces++;
ace_list++;
}
/* Create ACL from list of ACEs */
result = make_sec_acl(ACL_REVISION, num_aces, aces);
free(aces);
return result;
}
开发者ID:AIdrifter,项目名称:samba,代码行数:40,代码来源:se_access_check_utils.c
示例8: add_zone
void
add_zone(zonetbl_t *tbl, char *str)
{
zonename_t *entp;
zoneid_t id;
char *cp;
/*
* str should be either the name of a configured zone, or the
* id of a running zone. If str is a zone name, store the name
* in the table; otherwise, just store the id.
*/
if (zone_get_id(str, &id) != 0) {
Die(gettext("unknown zone -- %s\n"), str);
/*NOTREACHED*/
}
/* was zone specified by name or id? */
errno = 0;
if (id == (zoneid_t)strtol(str, &cp, 0) && errno == 0 && cp != str &&
*cp == '\0') {
/* found it by id, don't store the name */
str = NULL;
}
if (tbl->z_size == tbl->z_nent) { /* reallocation */
if ((tbl->z_size *= 2) == 0)
tbl->z_size = 4; /* first time */
tbl->z_list =
Realloc(tbl->z_list, tbl->z_size * sizeof (zonename_t));
}
entp = &tbl->z_list[tbl->z_nent++];
if (str)
(void) strlcpy(entp->z_name, str, ZONENAME_MAX);
else
entp->z_name[0] = '\0';
entp->z_id = id;
}
开发者ID:mikess,项目名称:illumos-gate,代码行数:39,代码来源:prtable.c
示例9: Realloc
// Adds an empty row at the end of the value buffer. The row will be
// marked invalid until the first value is set in the row. This will
// re-allocate the existing value buffer. If you know beforehand how
// many rows will exist in the table it is more efficient to use
// one SetNumRows(N) instead of N times AddRow()! The method returns
// the index of the newly added row. The row will be filled with
// the row attribute's default values.
int CValueTable::AddRow()
{
if (NumRows >= AllocatedRows)
{
int NewNumRows = AllocatedRows + AllocatedRows;
if (NewNumRows == 0) NewNumRows = 10;
Realloc(RowPitch, NewNumRows);
}
if (Flags.Is(_TrackModifications))
{
if (FirstNewRowIndex > NumRows) FirstNewRowIndex = NumRows;
RowStateBuffer[NumRows] |= NewRow;
++NewRowsCount;
Flags.Set(_IsModified);
}
//UserData.Append(NULL);
SetRowToDefaultValues(NumRows++); // Copy to stack, then increment, then call. Intended, don't change.
return NumRows - 1;
}
开发者ID:moltenguy1,项目名称:deusexmachina,代码行数:29,代码来源:ValueTable.cpp
示例10: msgput
static void
msgput(msginfo *m, const char *b, int n)
{
char *msg, *msg0, *msgend;
const char *be;
ftnlen msglen0;
msg = m->msg;
msgend = m->msgend;
be = b + n;
while(b < be) {
if (msg >= msgend) {
msglen0 = m->msglen;
msg0 = m->msg0 = (char*)
Realloc(m->msg0, m->msglen += MSGGULP);
msg = msg0 + msglen0;
m->msgend = msg0 + m->msglen;
}
*msg++ = *b++;
}
m->msg = msg;
}
开发者ID:ChinaQuants,项目名称:Ipopt,代码行数:22,代码来源:readsol.c
示例11: ERR_add_error_data
void ERR_add_error_data(int num, ...)
{
va_list args;
int i,n,s;
char *str,*p,*a;
s=64;
str=Malloc(s+1);
if (str == NULL) return;
str[0]='\0';
va_start(args, num);
n=0;
for (i=0; i<num; i++)
{
a=va_arg(args, char*);
/* ignore NULLs, thanks to Bob Beck <[email protected]> */
if (a != NULL)
{
n+=strlen(a);
if (n > s)
{
s=n+20;
p=Realloc(str,s+1);
if (p == NULL)
{
Free(str);
return;
}
else
str=p;
}
strcat(str,a);
}
}
ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
va_end(args);
}
开发者ID:Apple-FOSS-Mirror,项目名称:Security,代码行数:39,代码来源:err.c
示例12: _log_cat_ibuf
/*
* Move internal buffer content to common buffer:
*/
static size_t _log_cat_ibuf( LogInfo log, const char *buf, size_t size )
{
size_t blen = strlen( buf );
if( blen ) {
if( size + blen >= log->ibuf_size ) {
char *ptr = Realloc( log->ibuf, ( ( size + blen ) * 2 ) + 1 );
if( !ptr ) {
return 0;
}
log->ibuf = ptr;
log->ibuf_size = ( size + blen ) * 2;
}
memcpy( log->ibuf + size, buf, blen );
size += blen - 1;
}
return size;
}
开发者ID:klopp,项目名称:klib,代码行数:25,代码来源:log.c
示例13: add_session_user
void add_session_user(const char *user)
{
fstring suser;
struct passwd *passwd;
if (!(passwd = Get_Pwnam(user)))
return;
fstrcpy(suser,passwd->pw_name);
if(!*suser)
return;
if( session_userlist && in_list(suser,session_userlist,False) )
return;
if( !session_userlist || (strlen(suser) + strlen(session_userlist) + 2 >= len_session_userlist) ) {
char *newlist;
if (len_session_userlist > 128 * PSTRING_LEN) {
DEBUG(3,("add_session_user: session userlist already too large.\n"));
return;
}
newlist = Realloc( session_userlist, len_session_userlist + PSTRING_LEN );
if( newlist == NULL ) {
DEBUG(1,("Unable to resize session_userlist\n"));
return;
}
if (!session_userlist) {
*newlist = '\0';
}
session_userlist = newlist;
len_session_userlist += PSTRING_LEN;
}
safe_strcat(session_userlist," ",len_session_userlist-1);
safe_strcat(session_userlist,suser,len_session_userlist-1);
}
开发者ID:Nymphetaminer,项目名称:dsl-n55u,代码行数:38,代码来源:password.c
示例14: smbw_setshared
/*****************************************************
set a variable in the shared area
*******************************************************/
void smbw_setshared(const char *name, const char *val)
{
int l1, l2;
char *var;
/* we don't allow variable overwrite */
if (smbw_getshared(name)) return;
lockit();
l1 = strlen(name)+1;
l2 = strlen(val)+1;
var = (char *)Realloc(variables, shared_size + l1+l2+4, True);
if (!var) {
DEBUG(0,("out of memory in smbw_setshared\n"));
exit(1);
}
variables = var;
SSVAL(&variables[shared_size], 0, l1);
SSVAL(&variables[shared_size], 2, l2);
safe_strcpy(&variables[shared_size] + 4, name, l1-1);
safe_strcpy(&variables[shared_size] + 4 + l1, val, l2-1);
shared_size += l1+l2+4;
lseek(shared_fd, 0, SEEK_SET);
if (write(shared_fd, variables, shared_size) != shared_size) {
DEBUG(0,("smbw_setshared failed (%s)\n", strerror(errno)));
exit(1);
}
unlockit();
}
开发者ID:DeezNuts12,项目名称:freestyledash,代码行数:41,代码来源:shared.c
示例15: add_domain_alias
/*************************************************************************
Routine to return the next entry in the smbdomainalias list.
*************************************************************************/
BOOL add_domain_alias(LOCAL_GRP **alss, int *num_alss, LOCAL_GRP *als)
{
if (alss == NULL || num_alss == NULL || als == NULL)
{
return False;
}
(*alss) = Realloc((*alss), ((*num_alss)+1) * sizeof(LOCAL_GRP));
if ((*alss) == NULL)
{
return False;
}
DEBUG(10,("adding alias %s(%s)\n", als->name, als->comment));
fstrcpy((*alss)[(*num_alss)].name , als->name);
fstrcpy((*alss)[(*num_alss)].comment, als->comment);
(*alss)[(*num_alss)].rid = als->rid;
(*num_alss)++;
return True;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:26,代码来源:aliasdb.c
示例16: sk_insert
int sk_insert(STACK *st, char *data, int loc)
{
char **s;
if(st == NULL) return 0;
if (st->num_alloc <= st->num+1)
{
s=(char **)Realloc((char *)st->data,
(unsigned int)sizeof(char *)*st->num_alloc*2);
if (s == NULL)
return(0);
st->data=s;
st->num_alloc*=2;
}
if ((loc >= (int)st->num) || (loc < 0))
st->data[st->num]=data;
else
{
int i;
char **f,**t;
f=(char **)st->data;
t=(char **)&(st->data[1]);
for (i=st->num; i>=loc; i--)
t[i]=f[i];
#ifdef undef /* no memmove on sunos :-( */
memmove( (char *)&(st->data[loc+1]),
(char *)&(st->data[loc]),
sizeof(char *)*(st->num-loc));
#endif
st->data[loc]=data;
}
st->num++;
st->sorted=0;
return(st->num);
}
开发者ID:Apple-FOSS-Mirror,项目名称:Security,代码行数:37,代码来源:stack.c
示例17: enqueue_kqueue_change
// Parameters are taken from EV_SET (see kevent(2))
static int
enqueue_kqueue_change(poller *p,uintptr_t ident,short filter,u_short flags,
u_int fflags,intptr_t data,void *udata){
// This unlikely event could occur if, for instance, every fd is being
// used, and on the last sysdep_poll() every one had event changes,
// and then a verdict was injected while the poller was blocked.... or
// (far more likely) in the case of programming error, heheh
if(p->kchanges >= p->csize){
typeof(p->csize) tmpcsize = p->csize * 2;
typeof(*p->cv) *tmpcv;
// If we've not yet been initialized, or reset, don't start
// growing buffers...that's a serious problem. Should this be
// changed, insert a p->csize check around the Kevent() failure
// case involving vector dump and reuse of implied first slot!
if(p->csize == 0){
bitch("Used with uninitialized poller\n");
return -1;
}
if((tmpcv = Realloc("kchange vector",p->cv,sizeof(*tmpcv) * tmpcsize)) == NULL){
// If the realloc failed, dump the current vector...
if(Kevent(p->kq,p->cv,p->kchanges,NULL,0,NULL)){
inc_stateexceptions();
return -1;
}
// Reinitialize the buffer. We're assured that there's
// room for at least one of us now by p->csize check
p->kchanges = 0;
}else{
p->cv = tmpcv;
p->csize = tmpcsize;
}
}
EV_SET(&p->cv[p->kchanges++],ident,filter,flags,fflags,data,udata);
return 0;
}
开发者ID:dankamongmen,项目名称:snare,代码行数:37,代码来源:poller.c
示例18: privilege_enum_account_rights
/*
list the rights for an account. This involves traversing the database
*/
NTSTATUS privilege_enum_account_rights(DOM_SID *sid,
uint32 *count,
char ***rights)
{
TDB_DATA key, nextkey;
char *right;
if (!tdb) {
return NT_STATUS_INTERNAL_ERROR;
}
*rights = NULL;
*count = 0;
for (key = tdb_firstkey(tdb); key.dptr; key = nextkey) {
nextkey = tdb_nextkey(tdb, key);
right = key.dptr;
if (privilege_sid_has_right(sid, right)) {
(*rights) = (char **)Realloc(*rights,sizeof(char *) * ((*count)+1));
if (! *rights) {
safe_free(nextkey.dptr);
free(key.dptr);
return NT_STATUS_NO_MEMORY;
}
(*rights)[*count] = strdup(right);
(*count)++;
}
free(key.dptr);
}
return NT_STATUS_OK;
}
开发者ID:Nymphetaminer,项目名称:dsl-n55u,代码行数:39,代码来源:privileges.c
示例19: prs_force_grow
BOOL prs_force_grow(prs_struct *ps, uint32 extra_space)
{
uint32 new_size = ps->buffer_size + extra_space;
char *new_data;
if(!UNMARSHALLING(ps) || !ps->is_dynamic) {
DEBUG(0,("prs_force_grow: Buffer overflow - unable to expand buffer by %u bytes.\n",
(unsigned int)extra_space));
return False;
}
if((new_data = Realloc(ps->data_p, new_size)) == NULL) {
DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n",
(unsigned int)new_size));
return False;
}
memset(&new_data[ps->buffer_size], '\0', (size_t)(new_size - ps->buffer_size));
ps->buffer_size = new_size;
ps->data_p = new_data;
return True;
}
开发者ID:jophxy,项目名称:samba,代码行数:24,代码来源:parse_prs.c
示例20: Post
void sTextControl::Engine(sInt pos,sInt count,sChar *insert)
{
sInt len;
sInt i;
if(Static)
return;
Post(DoneCmd);
Changed = 1;
len = sGetStringLen(Text);
if(insert)
{
Realloc(len+count+1);
for(i=len;i>=pos;i--)
Text[i+count] = Text[i];
sCopyMem(Text+pos,insert,count);
}
else
{
if(pos+count<=len)
sCopyMem(Text+pos,Text+pos+count,len-pos-count+1);
}
}
开发者ID:Ambrevar,项目名称:fr_public,代码行数:24,代码来源:apptext.cpp
注:本文中的Realloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论