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


C++ Mem_Alloc函数代码示例

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


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

示例1: Mem_Alloc

/*
================
idCollisionModelManagerLocal::ParseBrushes
================
*/
void idCollisionModelManagerLocal::ParseBrushes( idLexer *src, cm_model_t *model ) {
	cm_brush_t *b;
	int i, numPlanes;
	idVec3 normal;
	idToken token;

	if ( src->CheckTokenType( TT_NUMBER, 0, &token ) ) {
		model->brushBlock = (cm_brushBlock_t *) Mem_Alloc( sizeof( cm_brushBlock_t ) + token.GetIntValue() );
		model->brushBlock->bytesRemaining = token.GetIntValue();
		model->brushBlock->next = ( (byte *) model->brushBlock ) + sizeof( cm_brushBlock_t );
	}

	src->ExpectTokenString( "{" );
	while ( !src->CheckTokenString( "}" ) ) {
		// parse brush
		numPlanes = src->ParseInt();
		b = AllocBrush( model, numPlanes );
		b->numPlanes = numPlanes;
		src->ExpectTokenString( "{" );
		for ( i = 0; i < b->numPlanes; i++ ) {
			src->Parse1DMatrix( 3, normal.ToFloatPtr() );
			b->planes[i].SetNormal( normal );
			b->planes[i].SetDist( src->ParseFloat() );
		}
		src->ExpectTokenString( "}" );
		src->Parse1DMatrix( 3, b->bounds[0].ToFloatPtr() );
		src->Parse1DMatrix( 3, b->bounds[1].ToFloatPtr() );
		src->ReadToken( &token );
		if ( token.type == TT_NUMBER ) {
			b->contents = token.GetIntValue();		// old .cm files use a single integer
		} else {
			b->contents = ContentsFromString( token );
		}
		b->checkcount = 0;
		b->primitiveNum = 0;
		// filter brush into tree
		R_FilterBrushIntoTree( model, model->node, NULL, b );
	}
}
开发者ID:Justasic,项目名称:DOOM-3,代码行数:44,代码来源:CollisionModel_files.cpp

示例2: R_WritePalTGA

/*
================
R_WritePalTGA
================
*/
void R_WritePalTGA( const char *filename, const byte *data, const byte *palette, int width, int height, bool flipVertical ) {
	byte	*buffer;
	int		i;
	int		bufferSize = (width * height) + (256 * 3) + 18;
	int     palStart = 18;
	int     imgStart = 18 + (256 * 3);

	buffer = (byte *)Mem_Alloc( bufferSize );
	memset( buffer, 0, 18 );
	buffer[1] = 1;		// color map type
	buffer[2] = 1;		// uncompressed color mapped image
	buffer[5] = 0;		// number of palette entries (lo)
	buffer[6] = 1;		// number of palette entries (hi)
	buffer[7] = 24;		// color map bpp
	buffer[12] = width&255;
	buffer[13] = width>>8;
	buffer[14] = height&255;
	buffer[15] = height>>8;
	buffer[16] = 8;	// pixel size
	if ( !flipVertical ) {
		buffer[17] = (1<<5);	// flip bit, for normal top to bottom raster order
	}

	// store palette, swapping rgb to bgr
	for ( i=palStart ; i<imgStart ; i+=3 ) {
		buffer[i] = palette[i-palStart+2];		// blue
		buffer[i+1] = palette[i-palStart+1];		// green
		buffer[i+2] = palette[i-palStart+0];		// red
	}

	// store the image data
	for ( i=imgStart ; i<bufferSize ; i++ ) {
		buffer[i] = data[i-imgStart];
	}

	fileSystem->WriteFile( filename, buffer, bufferSize );

	Mem_Free (buffer);
}
开发者ID:Debug-,项目名称:dhewm3,代码行数:44,代码来源:Image_files.cpp

示例3: LoadBoardFiles

/*
=============================
idGameBustOutWindow::LoadBoardFiles
=============================
*/
void idGameBustOutWindow::LoadBoardFiles( void ) {
	int i;
	int w,h;
	ID_TIME_T time;
	int boardSize;
	byte *currentBoard;

	if ( boardDataLoaded ) {
		return;
	}

	boardSize = 9 * 12 * 4;
	levelBoardData = (byte*)Mem_Alloc( boardSize * numLevels );

	currentBoard = levelBoardData;

	for ( i=0; i<numLevels; i++ ) {
		byte *pic;
		idStr	name = "guis/assets/bustout/level";
		name += (i+1);
		name += ".tga";

		R_LoadImage( name, &pic, &w, &h, &time, false );

		if ( pic != NULL ) {
			if ( w != 9 || h != 12 ) {
				common->DWarning( "Hell Bust-Out level image not correct dimensions! (%d x %d)", w, h );
			}

			memcpy( currentBoard, pic, boardSize );
			Mem_Free(pic);
		}

		currentBoard += boardSize;
	}

	boardDataLoaded = true;
}
开发者ID:Salamek,项目名称:Shadow-of-Dust,代码行数:43,代码来源:GameBustOutWindow.cpp

示例4: __FAT_Initialize

s32 __FAT_Initialize(u32 *queuehandle)
{
	/* Heap space */
	//static u32 heapspace[0x8000] ATTRIBUTE_ALIGN(32);
	static u32 heapspace[0x7000] ATTRIBUTE_ALIGN(32);

	void *buffer = NULL;
	s32   ret;

	/* Initialize memory heap */
	ret = Mem_Init(heapspace, sizeof(heapspace));
	if (ret < 0)
		return ret;

	/* Initialize timer subsystem */
	ret = Timer_Init();
	if (ret < 0)
		return ret;

	/* Allocate queue buffer */
	buffer = Mem_Alloc(0x80);
	if (!buffer)
		return IPC_ENOMEM;

	/* Create message queue */
	ret = os_message_queue_create(buffer, 32);
	if (ret < 0)
		return ret;

	/* Register device */
	os_device_register(DEVICE_FAT, ret);
	os_device_register("$", ret);

	/* Copy queue handler */
	*queuehandle = ret;

	return 0;
}
开发者ID:TCCQ,项目名称:d2x-cios,代码行数:38,代码来源:main.c

示例5: MA_AddMaterial

int MA_AddMaterial( const char *materialName )
{


	maMaterialNode_t	**destNode;
	maGlobal.model->materialNodes.Get( materialName, &destNode );
	
	if( destNode )
	{
		maMaterialNode_t *matNode = *destNode;
		
		//Iterate down the tree until we get a file
		while( matNode && !matNode->file )
		{
			matNode = matNode->child;
		}
		
		if( matNode && matNode->file )
		{
		
			//Got the file
			maMaterial_t	*material;
			material = ( maMaterial_t * ) Mem_Alloc( sizeof( maMaterial_t ) );
			memset( material, 0, sizeof( maMaterial_t ) );
			
			//Remove the OS stuff
			idStr qPath;
			qPath = fileSystem->OSPathToRelativePath( matNode->file->path );
			
			strcpy( material->name, qPath.c_str() );
			
			maGlobal.model->materials.Append( material );
			return maGlobal.model->materials.Num() - 1;
		}
	}
	
	return -1;
}
开发者ID:revelator,项目名称:MHDoom,代码行数:38,代码来源:Model_ma.cpp

示例6: EdgeIntersection

/*
====================
EdgeIntersection

Creates a new optVertex_t where the line segments cross.
This should only be called if PointsStraddleLine returned true

Will return NULL if the lines are colinear
====================
*/
static	optVertex_t* EdgeIntersection( const optVertex_t* p1, const optVertex_t* p2,
									   const optVertex_t* l1, const optVertex_t* l2, optimizeGroup_t* opt )
{
	float	f;
	idDrawVert*	v;
	idVec3	dir1, dir2, cross1, cross2;
	
	dir1 = p1->pv - l1->pv;
	dir2 = p1->pv - l2->pv;
	cross1 = dir1.Cross( dir2 );
	
	dir1 = p2->pv - l1->pv;
	dir2 = p2->pv - l2->pv;
	cross2 = dir1.Cross( dir2 );
	
	if( cross1[2] - cross2[2] == 0 )
	{
		return NULL;
	}
	
	f = cross1[2] / ( cross1[2] - cross2[2] );
	
	// FIXME: how are we freeing this, since it doesn't belong to a tri?
	v = ( idDrawVert* )Mem_Alloc( sizeof( *v ), TAG_TOOLS );
	memset( v, 0, sizeof( *v ) );
	
	v->xyz = p1->v.xyz * ( 1.0 - f ) + p2->v.xyz * f;
	idVec3 normal = p1->v.GetNormal() * ( 1.0 - f ) + p2->v.GetNormal() * f;
	normal.Normalize();
	v->SetNormal( normal );
	
	idVec2 st;
	st.x = p1->v.GetTexCoordS() * ( 1.0 - f ) + p2->v.GetTexCoordS() * f;
	st.y = p1->v.GetTexCoordT() * ( 1.0 - f ) + p2->v.GetTexCoordT() * f;
	v->SetTexCoord( st );
	
	return FindOptVertex( v, opt );
}
开发者ID:BielBdeLuna,项目名称:RBDoom3BFG-mirrored,代码行数:48,代码来源:optimize.cpp

示例7: CL_InitParticles

/*
================
CL_InitParticles

================
*/
void CL_InitParticles( void )
{
	int	i;

	cl_particles = Mem_Alloc( cls.mempool, sizeof( particle_t ) * GI->max_particles );
	CL_ClearParticles ();

	// this is used for EF_BRIGHTFIELD
	for( i = 0; i < NUMVERTEXNORMALS; i++ )
	{
		cl_avelocities[i][0] = Com_RandomLong( 0, 255 ) * 0.01f;
		cl_avelocities[i][1] = Com_RandomLong( 0, 255 ) * 0.01f;
		cl_avelocities[i][2] = Com_RandomLong( 0, 255 ) * 0.01f;
	}

	tracerred = Cvar_Get( "tracerred", "0.8", 0, "tracer red component weight ( 0 - 1.0 )" );
	tracergreen = Cvar_Get( "tracergreen", "0.8", 0, "tracer green component weight ( 0 - 1.0 )" );
	tracerblue = Cvar_Get( "tracerblue", "0.4", 0, "tracer blue component weight ( 0 - 1.0 )" );
	traceralpha = Cvar_Get( "traceralpha", "0.5", 0, "tracer alpha amount ( 0 - 1.0 )" );
	tracerspeed = Cvar_Get( "tracerspeed", "6000", 0, "tracer speed" );
	tracerlength = Cvar_Get( "tracerlength", "0.8", 0, "tracer length factor" );
	traceroffset = Cvar_Get( "traceroffset", "30", 0, "tracer starting offset" );
}
开发者ID:Xash3DLinux,项目名称:xash3dlinux,代码行数:29,代码来源:gl_rpart.c

示例8: new

void *idClass::operator new( size_t s, int, int, char *, int )
{
	int *p;
	
	s += sizeof( int );
	p = ( int * )Mem_Alloc( s );
	*p = s;
	memused += s;
	numobjects++;
	
#ifdef ID_DEBUG_UNINITIALIZED_MEMORY
	unsigned long *ptr = ( unsigned long * )p;
	int size = s;
	assert( ( size & 3 ) == 0 );
	size >>= 3;
	for( int i = 1; i < size; i++ )
	{
		ptr[i] = 0xcdcdcdcd;
	}
#endif
	
	return p + 1;
}
开发者ID:revelator,项目名称:MHDoom,代码行数:23,代码来源:Class.cpp

示例9:

/*
================
Sys_GetClipboardData
================
*/
char *Sys_GetClipboardData(void)
{
	char *data = NULL;
	char *cliptext;

	if (OpenClipboard(NULL) != 0) {
		HANDLE hClipboardData;

		if ((hClipboardData = GetClipboardData(CF_TEXT)) != 0) {
			if ((cliptext = (char *)GlobalLock(hClipboardData)) != 0) {
				data = (char *)Mem_Alloc(GlobalSize(hClipboardData) + 1);
				strcpy(data, cliptext);
				GlobalUnlock(hClipboardData);

				strtok(data, "\n\r\b");
			}
		}

		CloseClipboard();
	}

	return data;
}
开发者ID:AreaScout,项目名称:dante-doom3-odroid,代码行数:28,代码来源:win_main.cpp

示例10: cidr_get_mask

/* Get the netmask bits */
uint8_t *
cidr_get_mask(const CIDR *addr)
{
	uint8_t *toret;

	if(addr==NULL)
	{
		errno = EFAULT;
		return(NULL);
	}

	toret = Mem_Alloc(16*sizeof(uint8_t));
	if(toret==NULL)
	{
		errno = ENOMEM;
		return(NULL);
	}

	/* Copy 'em in */
	memcpy(toret, addr->mask, sizeof(addr->mask));

	return(toret);
}
开发者ID:xushiwei,项目名称:nfs-ganesha,代码行数:24,代码来源:cidr_get.c

示例11: Mem_Alloc

/*
================
idCollisionModelManagerLocal::ParsePolygons
================
*/
void idCollisionModelManagerLocal::ParsePolygons( idLexer *src, cm_model_t *model ) {
	cm_polygon_t *p;
	int i, numEdges;
	idVec3 normal;
	idToken token;

	if ( src->CheckTokenType( TT_NUMBER, 0, &token ) ) {
		model->polygonBlock = (cm_polygonBlock_t *) Mem_Alloc( sizeof( cm_polygonBlock_t ) + token.GetIntValue() );
		model->polygonBlock->bytesRemaining = token.GetIntValue();
		model->polygonBlock->next = ( (byte *) model->polygonBlock ) + sizeof( cm_polygonBlock_t );
	}

	src->ExpectTokenString( "{" );
	while ( !src->CheckTokenString( "}" ) ) {
		// parse polygon
		numEdges = src->ParseInt();
		p = AllocPolygon( model, numEdges );
		p->numEdges = numEdges;
		src->ExpectTokenString( "(" );
		for ( i = 0; i < p->numEdges; i++ ) {
			p->edges[i] = src->ParseInt();
		}
		src->ExpectTokenString( ")" );
		src->Parse1DMatrix( 3, normal.ToFloatPtr() );
		p->plane.SetNormal( normal );
		p->plane.SetDist( src->ParseFloat() );
		src->Parse1DMatrix( 3, p->bounds[0].ToFloatPtr() );
		src->Parse1DMatrix( 3, p->bounds[1].ToFloatPtr() );
		src->ExpectTokenType( TT_STRING, 0, &token );
		// get material
		p->material = declManager->FindMaterial( token );
		p->contents = p->material->GetContentFlags();
		p->checkcount = 0;
		// filter polygon into tree
		R_FilterPolygonIntoTree( model, model->node, NULL, p );
	}
}
开发者ID:CecilHarvey,项目名称:DOOM-3,代码行数:42,代码来源:CollisionModel_files.cpp

示例12: disk_read

DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, BYTE count)
{
    void *buffer;

    u32 len;
    s32 ret = 0;

    /* Buffer length */
    len = (count * SECTOR_SZ);

    /* Allocate buffer */
    buffer = Mem_Alloc(count * 512);
    if (!buffer)
        return RES_ERROR;

    /* Read sectors */
    switch (drv) {
    case DRIVE_SDHC:
        /* Read SD sectors */
        ret = sdio_ReadSectors(sector, count, buffer);
        break;

    case DRIVE_EHCI:
        /* Read USB sectors */
        ret = ehci_ReadSectors(sector, count, buffer);
        break;
    }

    /* Copy buffer */
    if (ret)
        memcpy(buff, buffer, len);

    /* Free buffer */
    Mem_Free(buffer);

    return (ret) ? RES_OK : RES_ERROR;
}
开发者ID:shadowbladeZ,项目名称:fat-module,代码行数:37,代码来源:diskio.c

示例13: Free

/*
============
idScriptObject::SetType

Allocates an object and initializes memory.
============
*/
bool idScriptObject::SetType( const char *typeName )
{
	size_t size;
	idTypeDef *newtype;
	
	// lookup the type
	newtype = gameLocal.program.FindType( typeName );
	
	// only allocate memory if the object type changes
	if( newtype != type )
	{
		Free();
		if( !newtype )
		{
			gameLocal.DWarning( "idScriptObject::SetType: Unknown type '%s'", typeName );
			return false;
		}
		
		if( !newtype->Inherits( &type_object ) )
		{
			gameLocal.DWarning( "idScriptObject::SetType: Can't create object of type '%s'.  Must be an object type.", newtype->Name() );
			return false;
		}
		
		// set the type
		type = newtype;
		
		// allocate the memory
		size = type->Size();
		data = ( byte * )Mem_Alloc( size );
	}
	
	// init object memory
	ClearObject();
	
	return true;
}
开发者ID:revelator,项目名称:MHDoom,代码行数:44,代码来源:Script_Program.cpp

示例14: WriteTGA24

static void WriteTGA24 (const char *filename, const byte * data, int width, int height, int offset)
{
	int i, size;
	byte *buffer;
	qFILE file;

	size = width * height * 3;
	/* allocate a buffer and set it up */
	buffer = (byte *)Mem_Alloc(size + TGA_HEADER_SIZE);
	memset(buffer, 0, TGA_HEADER_SIZE);
	buffer[2] = 2;
	buffer[12] = width & 255;
	buffer[13] = width >> 8;
	buffer[14] = height & 255;
	buffer[15] = height >> 8;
	buffer[16] = 24;
	/* create top-down TGA */
	buffer[17] = 32;

	/* swap rgb to bgr */
	for (i = 0; i < size; i += 3) {
		buffer[i + TGA_HEADER_SIZE] = data[i*2 + offset + 2];	/* blue */
		buffer[i + TGA_HEADER_SIZE + 1] = data[i*2 + offset + 1];	/* green */
		buffer[i + TGA_HEADER_SIZE + 2] = data[i*2 + offset + 0];	/* red */
	}

	/* write it and free the buffer */
	if (FS_OpenFile(filename, &file, FILE_WRITE) > 0)
		Sys_Error("Unable to open %s for writing", filename);

	FS_Write(buffer, size + TGA_HEADER_SIZE, &file);

	/* close the file */
	FS_CloseFile(&file);
	Mem_Free(buffer);
}
开发者ID:kevlund,项目名称:ufoai,代码行数:36,代码来源:lightmap.c

示例15: new

void * idClass::operator new( size_t s, int, int, char *, int ) {
	int *p;

	s += sizeof( int );
//RAVEN BEGIN
//amccarthy: Added memory allocation tag
	p = (int *)Mem_Alloc( s, MA_CLASS );
//RAVEN END
	*p = s;
	memused += s;
	numobjects++;

#ifdef ID_DEBUG_MEMORY
	unsigned long *ptr = (unsigned long *)p;
	int size = s;
	assert( ( size & 3 ) == 0 );
	size >>= 3;
	for ( int i = 1; i < size; i++ ) {
		ptr[i] = 0xcdcdcdcd;
	}
#endif

	return p + 1;
}
开发者ID:ET-NiK,项目名称:amxxgroup,代码行数:24,代码来源:Class.cpp


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