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


C++ reallocate函数代码示例

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


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

示例1: fopen

char *getDecodedMessage(const char *inputCodeFile, const char *key, int *status) {
    FILE *file = fopen(inputCodeFile, "r");
    if (file == NULL) {
        *status = INPUT_FILE_NOT_FOUND;
        return NULL;
    }
    char *decodedMessage = allocate(sizeof(char));
    char input;
    int position;
    int reallocValue = 1;
    int count = 0;

    while (true) {
        if (count == reallocValue) {
            reallocValue *= 2;
            decodedMessage = reallocate(decodedMessage, sizeof(char) * reallocValue);
        }
        int readStatus = fscanf(file, "[%d]", &position);
        if (readStatus == 1) {
            int index = position < 0 ? position * -1 : position;
            char value = key[index - 1];
            input = position < 0 ? toupper(value) : value;
        } else if (readStatus == EOF) {
            break;
        } else {
            fscanf(file, "%c", &input);
        }
        decodedMessage[count] = input;
        count++;
    }
    decodedMessage = (char*) reallocate(decodedMessage, sizeof(char) * (count + 1));
    decodedMessage[count] = '\0';
    fclose(file);
    return decodedMessage;
}
开发者ID:abztracta,项目名称:westerdals,代码行数:35,代码来源:secretCoder.c

示例2: reallocate

void TBScrollBoxImpl::refresh() {
    Requisition req;
    scrollbox_->request(req);
    start_ = 0;
    reallocate();
    redraw();
}
开发者ID:PNCG,项目名称:neuron,代码行数:7,代码来源:scrbox.cpp

示例3: reallocate

void Array::addAt( Object& toAdd, int atIndex )

// Summary -----------------------------------------------------------------
//
//      Adds the given object to the array at the given index.  If there
//      is an object already at that index, destroys the object.
//
// Parameters
//
//      toAdd
//
//      The object we are to add to the array.  Once the object is
//      added, it is owned by the array.
//
//      atIndex
//
//      The index at which to add the object.
//
// End ---------------------------------------------------------------------
{

	if( atIndex > upperbound )
    {
		reallocate( atIndex - lowerbound + 1 );
    }

    if ( theArray[ atIndex ] != ZERO )
    {
        delete theArray[ atIndex ];
        itemsInContainer--;
    }
	theArray[ atIndex ] = &toAdd;
	itemsInContainer++;
}
开发者ID:mostwanteddtm,项目名称:MicroSO,代码行数:34,代码来源:array.cpp

示例4: readline_buf

/* Reads in one line of source code and run it through the partial
 * preprocessor. The return value is zero if the file has reached the
 * end or if the file can't be read.
 */
static int readline_buf(CparsePP *ppp, const char *inbuf)
{
    int size, i = 1;
    int prev, ch;

    ch = inbuf[0];
    if (ch == '\0')
	return 0;
    prev = '\0';
    for (size = 0 ; ch != '\0' ; ++size) {
		if (ch == '\n' && prev != '\\')
		    break;
		if (size + 1 == ppp->linealloc) {
			ppp->linealloc *= 2;
			ppp->line = reallocate(ppp->line, ppp->linealloc);
		}
		ppp->line[size] = ch;
		prev = ch;
		ch = inbuf[i++];
    }
    ppp->endline = ch != '\0';
    ppp->line[size] = '\0';

    seq(ppp);

    nextline(ppp->cl, NULL);
    return 1;
}
开发者ID:0xroot,项目名称:radare2,代码行数:32,代码来源:pp.c

示例5: readline

/* Reads in one line of source code and run it through the partial
 * preprocessor. The return value is zero if the file has reached the
 * end or if the file can't be read.
 */
static int readline(CparsePP *ppp, FILE *infile)
{
    int size;
    int prev, ch;

    ch = fgetc(infile);
    if (ch == EOF)
	return 0;
    prev = EOF;
    for (size = 0 ; ch != EOF ; ++size) {
	if (ch == '\n' && prev != '\\')
	    break;
	if (size + 1 == ppp->linealloc) {
	    ppp->linealloc *= 2;
	    ppp->line = reallocate(ppp->line, ppp->linealloc);
	}
	ppp->line[size] = ch;
	prev = ch;
	ch = fgetc(infile);
    }
    if (ferror(infile)) {
	error(errFileIO);
	return 0;
    }
    ppp->endline = ch != EOF;
    ppp->line[size] = '\0';

    seq(ppp);

    nextline(ppp->cl, NULL);
    return 1;
}
开发者ID:0xroot,项目名称:radare2,代码行数:36,代码来源:pp.c

示例6: recordaddress

/* Adds an address to the collection. addr is the address, offset is
 * the (presumed) offset within the memory segment, size is the size
 * of the chunk of memory starting at that address, and name is the
 * name associated with that chunk. The largest chunk in that memory
 * address will determine which name is used to name the memory
 * segment.
 */
void recordaddress(long address, long offset, long size, char const *name)
{
    static int allocated = 0;
    long base;
    int i;

    base = address - offset;
    for (i = 0 ; i < addrcount ; ++i)
	if (addrs[i].address == base)
	    break;
    if (i == addrcount) {
	if (addrcount == allocated) {
	    allocated = allocated ? 2 * allocated : 4;
	    addrs = reallocate(addrs, allocated * sizeof *addrs);
	    memset(addrs + addrcount, 0,
		   (allocated - addrcount) * sizeof *addrs);
	}
	++addrcount;
	addrs[i].address = base;
    }
    ++addrs[i].count;
    if (!*addrs[i].name || addrs[i].maxchunk < size) {
	strcpy(addrs[i].name, name);
	addrs[i].maxchunk = size;
    }
    if (!addrs[i].from || addrs[i].from > address)
	addrs[i].from = address;
    if (addrs[i].to < address + size)
	addrs[i].to = address + size;
}
开发者ID:BR903,项目名称:ELFkickers,代码行数:37,代码来源:address.c

示例7: readHeaderBlock

// Read one file header block. Returns:
//   -1 ... this was the last block
//    0 ... there is at least one more block left
//    1 ... error occured during reading the block
// Arguments:
//   f         ... pointer to file for reading
//   debugMode ... debug messages flag
//   fileName  ... name of the file
//   buf       ... pointer to header buffer,
//                 enlarged (reallocated) for current block
//   bufOffset ... pointer to buffer size, increased for current block size
int readHeaderBlock(FILE *f, int debugMode, const char *fileName, char **buf,
        int *bufOffset)
{
    char *tmpBuf;
    int error, blockHeader[blockHeaderSize], swap;

    // Get size of file header block.
    swap = readBlockHeader(f, fileName, debugMode, blockHeader, sizeof(char));
    if(swap < 0) return 1;    // Error.

    // Allocate space for buffer.
    tmpBuf = reallocate(debugMode, *buf,
            (*bufOffset + blockHeader[0] + 1) * sizeof(char));
    if(tmpBuf == NULL) return 1;    // Error.
    *buf = tmpBuf;


    // Read file header block.
    error = readBlockData(f, fileName, debugMode, *buf + *bufOffset, bufOffset,
            sizeof(char), blockHeader[0], 0);
    if(error == 1) return 1;    // Error.
    (*buf)[*bufOffset] = 0;

    // Read trailer of file header block.
    error = readBlockTrailer(f, fileName, debugMode, swap,
            blockHeader[blockHeaderSize - 1]);
    if(error == 1) return 1;    // Error.

    if(strstr(*buf, "$&%#")) return -1;    // End of block.

    return 0;    // There is more.
}
开发者ID:xanderhsia,项目名称:pyopus,代码行数:43,代码来源:hspice_read.c

示例8: realloc

/*
 * Implementation of stdlib realloc.
 */
void * realloc(void *ptr, size_t size) {
    AllocUnit *au, *newAU;
    size_t paddedSize;

    if (size == 0) {
        free(ptr);
        return NULL;
    }
    paddedSize = padSize(size);
    if (!init()) {
        errno = ENOMEM;
        return NULL;
    }

    au = findAU(startHeap, (uintptr_t) ptr); 
    
    if (au == NULL || ptr == NULL) {
        return malloc(size);
    }

    newAU = reallocate(au, paddedSize);
    if (newAU == NULL) {
        errno = ENOMEM;
        return NULL;
    }
    if (debugMalloc()) {
        printf("MALLOC: realloc(%p,%zu)    =>   (ptr=%p, size=%zu)\n",ptr,
                size,newAU->memLoc,newAU->size); 
    }
    return newAU->memLoc;
}
开发者ID:devansc,项目名称:OS,代码行数:34,代码来源:malloc.c

示例9: new_set

/*
 * new_set() allocates another structure for a new set in the sets array and
 * increments the cur_set to index into the sets array for the new set.
 */
__private_extern__
void
new_set(void)
{
    long i;

	if(cur_set + 2 > nsets){
	    sets = reallocate(sets,
			      (nsets + NSETS_INCREMENT) * sizeof(struct set));
	    for(i = 0; i < NSETS_INCREMENT; i++){
		memset(sets + nsets + i, '\0', sizeof(struct set));
		sets[nsets + i].link_edit_common_object =
			allocate(sizeof(struct object_file));
		memset(sets[nsets + i].link_edit_common_object, '\0',
			sizeof(struct object_file));
		sets[nsets + i].link_edit_section_maps =
			allocate(sizeof(struct section_map));
		memset(sets[nsets + i].link_edit_section_maps, '\0',
			sizeof(struct section_map));
		sets[nsets + i].link_edit_common_section =
			allocate(sizeof(struct section));
		memset(sets[nsets + i].link_edit_common_section, '\0',
		       sizeof(struct section));
	    }
	    nsets += NSETS_INCREMENT;
	}
	cur_set++;
}
开发者ID:Apple-FOSS-Mirror,项目名称:cctools,代码行数:32,代码来源:sets.c

示例10: delete_ssh

static void delete_ssh( const char *cmd )
{
    if ( !cmd || !cmd[0] ) return ;

    int curr = -1;
    unsigned int index = 0;
    char **retv = NULL;

    /**
     * This happens in non-critical time (After launching app)
     * It is allowed to be a bit slower.
     */
    char *path = allocate( strlen( cache_dir ) + strlen( SSH_CACHE_FILE )+3 );
    sprintf( path, "%s/%s", cache_dir, SSH_CACHE_FILE );
    FILE *fd = fopen ( path, "r" );

    if ( fd != NULL ) {
        char buffer[1024];
        while ( fgets( buffer,1024,fd ) != NULL ) {
            retv = reallocate( retv, ( index+2 )*sizeof( char* ) );
            buffer[strlen( buffer )-1] = '\0';
            retv[index] = strdup( buffer );
            retv[index+1] = NULL;

            if ( strcasecmp( retv[index], cmd ) == 0 ) {
                curr = index;
            }

            index++;
        }

        fclose( fd );
    }

    /**
     * Write out the last 25 results again.
     */
    fd = fopen ( path, "w" );

    if ( fd ) {

        for ( int i = 0; i < ( int )index && i < 20; i++ ) {
            if ( i != curr ) {
                fputs( retv[i], fd );
                fputc( '\n', fd );
            }
        }

        fclose( fd );
    }

    for ( int i=0; retv != NULL && retv[i] != NULL; i++ ) {
        free( retv[i] );
    }

    free( retv );

    free( path );

}
开发者ID:blueyed,项目名称:rofi,代码行数:60,代码来源:ssh-dialog.c

示例11: IRR_ASSERT

		//! Appends a string of the length l to this string.
		void stringc::append(const stringc& other, u32 length)
		{
			bool selfAppending = false;

			//handle self-appending
			if (this == &other)
				selfAppending = true;

			if (!selfAppending)
				other.Monitor->enter();
			Monitor->enter();

			IRR_ASSERT((other.Used - 1) > length);

			if (Used + length > Allocated)
				reallocate(Used + length);

			--Used;

			for (u32 l = 0; l < length; ++l)
				Array[l + Used] = other.Array[l];
			Used += length;

			// ensure proper termination
			Array[Used] = 0;
			++Used;

			if (!selfAppending)
				other.Monitor->exit();
			Monitor->exit();
		}
开发者ID:CowPlay,项目名称:engineSDK,代码行数:32,代码来源:stringc.cpp

示例12: reallocate

		//! Appends a string to this string
		void stringc::append(const stringc& other)
		{
			bool selfAppending = false;

			//handle self-appending
			if (this == &other)
				selfAppending = true;

			if (!selfAppending)
				other.Monitor->enter();
			Monitor->enter();

			--Used;
			u32 len = other.Used;

			if (Used + len > Allocated)
				reallocate(Used + len);

			for (u32 l = 0; l < len; ++l)
				Array[Used + l] = other.Array[l];

			Used += len;

			if (!selfAppending)
				other.Monitor->exit();
			Monitor->exit();
		}
开发者ID:CowPlay,项目名称:engineSDK,代码行数:28,代码来源:stringc.cpp

示例13: accumulator

/* Automatically reallocate storage for a buffer that has an unknown
 * final size.  To create a new accumulator, pass in old==NULL.  To
 * reuse an existing accumulator, pass it in as old.  The new desired
 * size in bytes is len.  If zerofill is non-zero, all bytes between
 * the old and new length will be zero filled.
 *
 * Call this every time before placing a new element in the
 * accumulator.  If you may place new elements non-sequentially, you
 * should set zerofill on every call for a given accumulator.
 *
 * If it's non-NULL, the argument 'old' points four bytes into an
 * allocated block. The four preceding bytes give the length of the
 * most recent allocation for that block. That's why we back up from
 * old to get the value for accumulator, which is a block of size
 * length+sizeof(unsigned int).
 */
void *
accumulator(void *old, unsigned int len, int zerofill)
{
    unsigned int *accumulator;     // points to length word, or NULL if a new accumulator
    unsigned int new_len;          // includes the length word
    unsigned int accum_length;     // includes the length word
    unsigned int old_accum_length; // includes the length word
    // The value stored in the length word includes the length word itself.

    // allocate something even if len==0
    new_len = (len ? len : 1) + sizeof(int);
    if (old == NULL) {
	accumulator = NULL;
	old_accum_length = sizeof(int);
    } else {
	accumulator = ((unsigned int *)old) - 1;
	old_accum_length = *accumulator;
    }
    if (new_len > old_accum_length) {
	accum_length = quantize_length(new_len);
	accumulator = (unsigned int *)reallocate(accumulator, accum_length);
	*accumulator = accum_length;
	if (zerofill) {
	    memset(((char *)accumulator)+old_accum_length, 0,
		   accum_length - old_accum_length);
	}
	return (void *)(accumulator+1);
    }
    return old;
}
开发者ID:ematvey,项目名称:NanoEngineer-1,代码行数:46,代码来源:allocate.c

示例14: reallocate

template<class T> void Tuple<T>::append(const Tuple<T>& t) {
    int old_sz = sz;
    reallocate(t.size()+size());
    assert(alloc_sz >= sz);
    for(int i=0; i<t.sz; i++)
	data[i+old_sz] = t.data[i];
}
开发者ID:CtopCsUtahEdu,项目名称:chill-dev,代码行数:7,代码来源:Tuple.c

示例15: buttonInit

// ----------------------------------------------------------------------------
void ToolBar::init()
{
    Editor* editor = Editor::getEditor();
    path icons = editor->getIconsLoc();
    m_bar      = editor->getGUIEnv()->addToolBar();
    m_bar->setMinSize(dimension2du(0,50));

    buttonInit(0,  TBI_NEW,         (icons + "new.png").c_str(),      _(L"New (ctrl+n)"));
    buttonInit(1,  TBI_OPEN,        (icons + "open.png").c_str(),     _(L"Open (ctrl+o)"));
    buttonInit(2,  TBI_SAVE,        (icons + "save.png").c_str(),     _(L"Save (ctrl+s)"));
    buttonInit(3,  TBI_EXPORT ,     (icons + "save_as.png").c_str(),  _(L"Export (ctrl+shift+s)"));
    buttonInit(4,  TBI_UNDO,        (icons + "undo.png").c_str(),     _(L"Undo (ctrl+z)"));
    buttonInit(5,  TBI_REDO,        (icons + "redo.png").c_str(),     _(L"Redo (ctrl+y)"));
    buttonInit(6,  TBI_SELECT,      (icons + "select.png").c_str(),   _(L"Select (shift+a)"));
    buttonInit(7,  TBI_MOVE,        (icons + "move.png").c_str(),     _(L"Move (shift+g)"));
    buttonInit(8,  TBI_ROTATE,      (icons + "rotate.png").c_str(),   _(L"Rotate (shift+r)"));
    buttonInit(9,  TBI_SCALE,       (icons + "scale.png").c_str(),    _(L"Scale (shift+s)"));
    buttonInit(10, TBI_DELETE,      (icons + "delete.png").c_str(),   _(L"Delete (del)"));
    buttonInit(11, TBI_CAM,         (icons + "cam1.png").c_str(),     _(L"Toggle camera mode (c)"));
    buttonInit(12, TBI_RECAM,       (icons + "cam2.png").c_str(),     _(L"Restore camera state (NUM1)"));
    buttonInit(13, TBI_DRIVELINE,   (icons + "spline.png").c_str(),   _(L"Select DriveLine (r)"));  
    buttonInit(14, TBI_HIDE_TERRAIN,(icons + "ht.png").c_str(),       _(L"Hide terrain (t)"));
    buttonInit(15, TBI_MUSIC,       (icons + "music.png").c_str(),    _(L"Music"));
    buttonInit(16, TBI_TRY,         (icons + "try.png").c_str(),      _(L"Try your track"));
    buttonInit(17, TBI_EXIT,        (icons + "exit.png").c_str(),     _(L"Quit (esc)"));

    reallocate();

} // init
开发者ID:Boyquotes,项目名称:stk-editor,代码行数:30,代码来源:toolbar.cpp


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