model_server/process/src/MemSeg.h.cxx
//-----------------------------------------------------
// MemorySegment::morecore
//
// Ask system for more memory 
//-----------------------------------------------------
:morecore
Ask system for more memory
: morecore Ask system for more memory
void MemorySegment::morecore (int block_num)
{
    char *ptr;
    char *end_ptr;
    unsigned size;
    if ( block_num < 8 )
	size = BLOCKSIZE;
    else
	size = 1 << (block_num + 3);
    ptr = (char*)sbrk (size);
    if (ptr == 0)
	return;
    free_list[block_num] = (MallocList*) ptr;
    end_ptr = ptr + size;
    size = 1 << (block_num + 3);
    end_ptr -= size;
    while (ptr < end_ptr) {
	((MallocList*)ptr)->flag = FREED;
	((MallocList*)ptr)->block_num = block_num;
	CHAIN ((MallocList*)ptr) = (MallocList*) (ptr + size);
	ptr += size;
    }
    ((MallocList*)ptr)->flag = FREED;
    ((MallocList*)ptr)->block_num = block_num;
    CHAIN (((MallocList*) ptr)) = 0;
}
void MemorySegment :: morecore ( int block_num ) { char * ptr ; char * end_ptr ; unsigned size ; if ( block_num < 8 ) size = BLOCKSIZE ; else size = 1 << ( block_num + 3 ) ; ptr = ( char * ) sbrk ( size ) ; if ( ptr == 0 ) return ; free_list [ block_num ] = ( MallocList * ) ptr ; end_ptr = ptr + size ; size = 1 << ( block_num + 3 ) ; end_ptr -= size ; while ( ptr < end_ptr ) { ( ( MallocList * ) ptr ) -> flag = FREED ; ( ( MallocList * ) ptr ) -> block_num = block_num ; CHAIN ( ( MallocList * ) ptr ) = ( MallocList * ) ( ptr + size ) ; ptr += size ; } ( ( MallocList * ) ptr ) -> flag = FREED ; ( ( MallocList * ) ptr ) -> block_num = block_num ; CHAIN ( ( ( MallocList * ) ptr ) ) = 0 ; }
MemorySegment::morecore
Ask system for more memory
MemorySegment :: morecore Ask system for more memory
// More core computes the block size from the block number and determines // a good chunk allocation size. This size is then requested to be allocated // by sbrk and then divided into chunks and linked together. // save new header and link the blocks together