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