您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ ALLOCMEM函数代码示例

51自学网 2021-06-01 19:34:41
  C++
这篇教程C++ ALLOCMEM函数代码示例写得很实用,希望能帮到您。

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

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

示例1: SFileSetHashTableSize

bool WINAPI SFileSetHashTableSize(HANDLE hMpq, DWORD dwNewTableSize){    SFILE_FIND_DATA sf;    TMPQArchive * ha = (TMPQArchive *)hMpq;    TFileNode ** pListFileToFree = NULL;    TFileNode ** pNewListFile = NULL;    TMPQHash * pOldHashTable = NULL;    TMPQHash * pNewHashTable = NULL;    TMPQHash * pTableToFree = NULL;    TMPQHash * pNewHash = NULL;    HANDLE hFind;    DWORD dwOldTableSize = ha->pHeader->dwHashTableSize;    DWORD dwIndex;    bool bFoundSomething = true;    int nError = ERROR_SUCCESS;    // Test the valid parameters    if(!IsValidMpqHandle(ha))        nError = ERROR_INVALID_HANDLE;    if(ha->dwFlags & MPQ_FLAG_READ_ONLY)        nError = ERROR_ACCESS_DENIED;    // New hash table size must be a power of two    if(dwNewTableSize & (dwNewTableSize - 1))        nError = ERROR_INVALID_PARAMETER;    // Allocate buffers for copy of the old hash table and new hash table    if(nError == ERROR_SUCCESS)    {        pOldHashTable = ALLOCMEM(TMPQHash, dwOldTableSize);        pNewHashTable = ALLOCMEM(TMPQHash, dwNewTableSize);        pNewListFile = ALLOCMEM(TFileNode *, dwNewTableSize);        if(pOldHashTable == NULL || pNewHashTable == NULL)            nError = ERROR_NOT_ENOUGH_MEMORY;    }
开发者ID:xkyve,项目名称:pseuwow-gamma,代码行数:35,


示例2: ReadMPQFileSingleUnit

// When this function is called, it is already ensured that the parameters are valid// (e.g. the "dwToRead + dwFilePos" is not greater than the file size)// TODO: Test for archives > 4GBstatic DWORD WINAPI ReadMPQFileSingleUnit(TMPQFile * hf, DWORD dwFilePos, BYTE * pbBuffer, DWORD dwToRead){    TMPQArchive * ha = hf->ha;    DWORD dwBytesRead = 0;    if(ha->FilePointer.QuadPart != hf->MpqFilePos.QuadPart)    {        SetFilePointer(ha->hFile, hf->MpqFilePos.LowPart, &hf->MpqFilePos.HighPart, FILE_BEGIN);        ha->FilePointer = hf->MpqFilePos;    }    // If the file is really compressed, decompress it.    // Otherwise, read the data as-is to the caller.    if(hf->pBlock->dwCSize < hf->pBlock->dwFSize)    {        if(hf->pbFileBuffer == NULL)        {            BYTE * inputBuffer = NULL;            int outputBufferSize = (int)hf->pBlock->dwFSize;            int inputBufferSize = (int)hf->pBlock->dwCSize;            hf->pbFileBuffer = ALLOCMEM(BYTE, outputBufferSize);            inputBuffer = ALLOCMEM(BYTE, inputBufferSize);            if(inputBuffer != NULL && hf->pbFileBuffer != NULL)            {                // Read the compressed file data                ReadFile(ha->hFile, inputBuffer, inputBufferSize, &dwBytesRead, NULL);                // Is the file compressed with PKWARE Data Compression Library ?                if(hf->pBlock->dwFlags & MPQ_FILE_COMPRESS_PKWARE)                    Decompress_pklib((char *)hf->pbFileBuffer, &outputBufferSize, (char *)inputBuffer, (int)inputBufferSize);                // Is it a file compressed by Blizzard's multiple compression ?                // Note that Storm.dll v 1.0.9 distributed with Warcraft III                // passes the full path name of the opened archive as the new last parameter                if(hf->pBlock->dwFlags & MPQ_FILE_COMPRESS_MULTI)                    SCompDecompress((char *)hf->pbFileBuffer, &outputBufferSize, (char *)inputBuffer, (int)inputBufferSize);            }            // Free the temporary buffer            if(inputBuffer != NULL)                FREEMEM(inputBuffer);        }        // Copy the file data, if any there        if(hf->pbFileBuffer != NULL)        {            memcpy(pbBuffer, hf->pbFileBuffer + dwFilePos, dwToRead);            dwBytesRead += dwToRead;        }    }    else    {        // Read the uncompressed file data        ReadFile(ha->hFile, pbBuffer, dwToRead, &dwBytesRead, NULL);        dwBytesRead = (int)dwBytesRead;    }    return (DWORD)dwBytesRead;}
开发者ID:Bootz,项目名称:TC-One,代码行数:63,


示例3: LoadMpqPatch_BSD0

static int LoadMpqPatch_BSD0(TMPQFile * hf, TPatchHeader * pPatchHeader){    LPBYTE pbDecompressed = NULL;    LPBYTE pbCompressed = NULL;    DWORD cbDecompressed = 0;    DWORD cbCompressed = 0;    DWORD dwBytesRead = 0;    int nError = ERROR_SUCCESS;    // Allocate space for compressed data    cbCompressed = pPatchHeader->dwXfrmBlockSize - SIZE_OF_XFRM_HEADER;    pbCompressed = ALLOCMEM(BYTE, cbCompressed);    if(pbCompressed == NULL)        nError = ERROR_SUCCESS;    // Read the compressed patch data    if(nError == ERROR_SUCCESS)    {        // Load the rest of the header        SFileReadFile((HANDLE)hf, pbCompressed, cbCompressed, &dwBytesRead);        if(dwBytesRead != cbCompressed)            nError = ERROR_FILE_CORRUPT;    }    // Get the uncompressed size of the patch    if(nError == ERROR_SUCCESS)    {        cbDecompressed = pPatchHeader->dwSizeOfPatchData - sizeof(TPatchHeader);        hf->pPatchHeader = (TPatchHeader *)ALLOCMEM(BYTE, pPatchHeader->dwSizeOfPatchData);        if(hf->pPatchHeader == NULL)            nError = ERROR_NOT_ENOUGH_MEMORY;    }    // Now decompress the patch data    if(nError == ERROR_SUCCESS)    {        // Copy the patch header        memcpy(hf->pPatchHeader, pPatchHeader, sizeof(TPatchHeader));        pbDecompressed = (LPBYTE)hf->pPatchHeader + sizeof(TPatchHeader);        // Uncompress or copy the patch data        if(cbCompressed < cbDecompressed)        {            Decompress_RLE(pbDecompressed, cbDecompressed, pbCompressed, cbCompressed);        }        else        {            assert(cbCompressed == cbDecompressed);            memcpy(pbDecompressed, pbCompressed, cbCompressed);        }    }    // Free buffers and exit    if(pbCompressed != NULL)        FREEMEM(pbCompressed);    return nError;}
开发者ID:milleniumcore,项目名称:CactusEMU,代码行数:57,


示例4: SAttrFileCreate

int SAttrFileCreate(TMPQArchive * ha){    TMPQAttr * pNewAttr;    int nError = ERROR_SUCCESS;    // There should NOW be any attributes    assert(ha->pAttributes == NULL);    pNewAttr = ALLOCMEM(TMPQAttr, 1);    if(pNewAttr != NULL)    {        // Pre-set the structure        pNewAttr->dwVersion = MPQ_ATTRIBUTES_V1;        pNewAttr->dwFlags = 0;        // Allocate array for CRC32        pNewAttr->pCrc32 = ALLOCMEM(TMPQCRC32, ha->pHeader->dwHashTableSize);        if(pNewAttr->pCrc32 != NULL)        {            pNewAttr->dwFlags |= MPQ_ATTRIBUTE_CRC32;            memset(pNewAttr->pCrc32, 0, sizeof(TMPQCRC32) * ha->pHeader->dwHashTableSize);        }        else            nError = ERROR_NOT_ENOUGH_MEMORY;        // Allocate array for FILETIME        pNewAttr->pFileTime = ALLOCMEM(TMPQFileTime, ha->pHeader->dwHashTableSize);        if(pNewAttr->pFileTime != NULL)        {            pNewAttr->dwFlags |= MPQ_ATTRIBUTE_FILETIME;            memset(pNewAttr->pFileTime, 0, sizeof(TMPQFileTime) * ha->pHeader->dwHashTableSize);        }        else            nError = ERROR_NOT_ENOUGH_MEMORY;        // Allocate array for MD5        pNewAttr->pMd5 = ALLOCMEM(TMPQMD5, ha->pHeader->dwHashTableSize);        if(pNewAttr->pMd5 != NULL)        {            pNewAttr->dwFlags |= MPQ_ATTRIBUTE_MD5;            memset(pNewAttr->pMd5, 0, sizeof(TMPQMD5) * ha->pHeader->dwHashTableSize);        }        else            nError = ERROR_NOT_ENOUGH_MEMORY;    }    // If something failed, then free the attributes structure    if(nError != ERROR_SUCCESS)    {        FreeMPQAttributes(pNewAttr);        pNewAttr = NULL;    }    ha->pAttributes = pNewAttr;    return nError;}
开发者ID:Artyom91,项目名称:OHBot,代码行数:56,


示例5: ShowTexfontMessage

// show (make active) a texfont message ---------------------------------------//void ShowTexfontMessage( texfontmsg_s *msg ){	ASSERT( msg != NULL );	//NOTE:	// messages of the same type will replace each other,	// whereas messages of different types will coexist.	// search for msg to replace (according to type)	int msgid = 0;	for ( msgid = 0; msgid < num_texfont_msgs; msgid++ ) {		if ( TexfontMsgs[ msgid ].msgtype == msg->msgtype ) {			FreeTexfontMessage( msgid );			msgid = num_texfont_msgs;			break;		}	}	// guard against table size overflow	if ( msgid >= MAX_TEXFONT_MESSAGES ) {		return;	}	// copy basic info	memcpy( &TexfontMsgs[ msgid ], msg, sizeof( texfontmsg_s ) );	// refalpha may be set explicitly to allow for oversaturated alpha starts	if ( msg->itexfont->Vtxs[ 0 ].A == 0 ) {		TexfontMsgs[ msgid ].curalpha = TexfontMsgs[ msgid ].refalpha;	} else {		TexfontMsgs[ msgid ].refalpha = msg->itexfont->Vtxs[ 0 ].A;		TexfontMsgs[ msgid ].curalpha = msg->itexfont->Vtxs[ 0 ].A;	}	// must make a copy of message string	TexfontMsgs[ msgid ].message = (char *) ALLOCMEM( strlen( msg->message ) + 1 );	if ( TexfontMsgs[ msgid ].message == NULL )		OUTOFMEM( 0 );	strcpy( TexfontMsgs[ msgid ].message, msg->message );	// must make a copy of itertexfont structure	TexfontMsgs[ msgid ].itexfont = (IterTexfont *) ALLOCMEM( sizeof( IterTexfont ) );	if ( TexfontMsgs[ msgid ].itexfont == NULL )		OUTOFMEM( 0 );	memcpy( TexfontMsgs[ msgid ].itexfont, msg->itexfont, sizeof( IterTexfont ) );	// one more active message	num_texfont_msgs++;}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:51,


示例6: CreatePackage

// create data package --------------------------------------------------------//PRIVATEint CreatePackage( const char* packname, const char *listname ){	ASSERT( packname != NULL );	ASSERT( listname != NULL );	#define MAX_DATA_FILES 4096	list_item_s *listitems = (list_item_s *) ALLOCMEM( MAX_DATA_FILES * sizeof( list_item_s ) );	if ( listitems == NULL ) {		return FALSE;	}	int numitems = ReadFileList( listname, listitems, MAX_DATA_FILES );	if ( numitems == -1 ) {		FREEMEM( listitems );		MakepackError();	}	if ( !WritePackageFile( packname, listitems, numitems ) ) {		FREEMEM( listitems );		MakepackError();	}	FREEMEM( listitems );	return TRUE;}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:29,


示例7: INPs_KeybInitHandler

// init keyboard code (alloc mem, setup tables, install handlers) -------------//void INPs_KeybInitHandler(){	// enable unicode character handling for keypress events	#if !SDL_VERSION_ATLEAST(2,0,0)	SDL_EnableUNICODE(SDL_ENABLE);#endif		// XXX: Not sure if this is needed either....	// prevent multiple inits	if ( sdl_keyb_init_done ) {		return;	}	// alloc key tables	KeyAdditional	= (keyaddctrl_s *) ALLOCMEM( sizeof( keyaddctrl_s ) );	// init all structs	memset( DepressedKeys,	0, sizeof( keyfunc_s ) );	memset( KeyAdditional,	0, sizeof( keyaddctrl_s ) );	memset( KeybFlags,		0, sizeof( keybflags_s ) );	KeybFlags->ConTogReleased = (byte)-1;/*	// grab input*/	sdl_keyb_init_done = TRUE;}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:33,


示例8: LoadMpqPatch_COPY

static int LoadMpqPatch_COPY(TMPQFile * hf, TPatchHeader * pPatchHeader){    int nError = ERROR_SUCCESS;    // Allocate space for patch header and compressed data    hf->pPatchHeader = (TPatchHeader *)ALLOCMEM(BYTE, pPatchHeader->dwSizeOfPatchData);    if(hf->pPatchHeader == NULL)        nError = ERROR_NOT_ENOUGH_MEMORY;    // Load the patch data and decide if they are compressed or not    if(nError == ERROR_SUCCESS)    {        LPBYTE pbPatchFile = (LPBYTE)hf->pPatchHeader;        // Copy the patch header itself        memcpy(pbPatchFile, pPatchHeader, sizeof(TPatchHeader));        pbPatchFile += sizeof(TPatchHeader);        // Load the rest of the patch        if(!SFileReadFile((HANDLE)hf, pbPatchFile, pPatchHeader->dwSizeOfPatchData - sizeof(TPatchHeader)))            nError = GetLastError();    }    return nError;}
开发者ID:milleniumcore,项目名称:CactusEMU,代码行数:25,


示例9: VaporTrailRegisterCustomType

// register object type for vapor trail ---------------------------------------//PRIVATEvoid VaporTrailRegisterCustomType(){	custom_type_info_s info;	memset( &info, 0, sizeof( info ) );	// always try to allocate template	vapor_type_template = (VaporTrail *) ALLOCMEM( sizeof( VaporTrail ) );	if ( vapor_type_template != NULL ) {		memset( vapor_type_template, 0, sizeof( VaporTrail ) );		VaporTrailInitDefaults( vapor_type_template );	}	info.type_name			= "vaportrail";	info.type_id			= 0x00000000;	info.type_size			= sizeof( VaporTrail );	info.type_template		= vapor_type_template;	info.type_flags			= CUSTOM_TYPE_DEFAULT;	info.callback_init		= VaporTrailInitType;	info.callback_instant	= VaporTrailInstantiate;	info.callback_destroy	= VaporTrailDestroy;	info.callback_animate	= VaporTrailAnimate;	info.callback_collide	= NULL;	info.callback_notify	= VaporTrailNotify;	info.callback_persist   = NULL;	vapor_type_id = OBJ_RegisterCustomType( &info );	CON_RegisterCustomType( info.type_id, VaporTrail_PropList );}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:31,


示例10: ReadMpqFilePatchFile

static int ReadMpqFilePatchFile(TMPQFile * hf, void * pvBuffer, DWORD dwToRead, LPDWORD pdwBytesRead){    DWORD dwBytesToRead = dwToRead;    DWORD dwBytesRead = 0;    int nError = ERROR_SUCCESS;    // Make sure that the patch file is loaded completely    if(hf->pbFileData == NULL)    {        // Load the original file and store its content to "pbOldData"        hf->pbFileData = ALLOCMEM(BYTE, hf->pFileEntry->dwFileSize);        hf->cbFileData = hf->pFileEntry->dwFileSize;        if(hf->pbFileData == NULL)            return ERROR_NOT_ENOUGH_MEMORY;        // Read the file data        if(hf->pFileEntry->dwFlags & MPQ_FILE_SINGLE_UNIT)            nError = ReadMpqFileSingleUnit(hf, hf->pbFileData, hf->cbFileData, &dwBytesRead);        else            nError = ReadMpqFile(hf, hf->pbFileData, hf->cbFileData, &dwBytesRead);        // Fix error code        if(nError == ERROR_SUCCESS && dwBytesRead != hf->cbFileData)            nError = ERROR_FILE_CORRUPT;        // Patch the file data        if(nError == ERROR_SUCCESS)            nError = PatchFileData(hf);        // Reset position to zero        hf->dwFilePos = 0;        dwBytesRead = 0;    }    // If there is something to read, do it    if(nError == ERROR_SUCCESS)    {        if(hf->dwFilePos < hf->cbFileData)        {            // Make sure we don't copy more than file size            if((hf->dwFilePos + dwToRead) > hf->cbFileData)                dwToRead = hf->cbFileData - hf->dwFilePos;            // Copy the appropriate amount of the file data to the caller's buffer            memcpy(pvBuffer, hf->pbFileData + hf->dwFilePos, dwToRead);            hf->dwFilePos += dwToRead;            dwBytesRead = dwToRead;        }        // Set the proper error code        nError = (dwBytesRead == dwBytesToRead) ? ERROR_SUCCESS : ERROR_HANDLE_EOF;    }    // Give the result to the caller    if(pdwBytesRead != NULL)        *pdwBytesRead = dwBytesRead;    return nError;}
开发者ID:Bootz,项目名称:StrawberryCore,代码行数:58,


示例11: CalculateMpqHashSha1

static bool CalculateMpqHashSha1(TMPQArchive * ha, PMPQ_SIGNATURE_INFO pSI, unsigned char * sha1_tail0, unsigned char * sha1_tail1, unsigned char * sha1_tail2) {    ULONGLONG BeginBuffer;    hash_state sha1_state_temp;    hash_state sha1_state;    LPBYTE pbDigestBuffer = NULL;    // Allocate buffer for creating the MPQ digest.    pbDigestBuffer = ALLOCMEM(BYTE, MPQ_DIGEST_UNIT_SIZE);    if (pbDigestBuffer == NULL)        return false;    // Initialize SHA1 state structure    sha1_init(&sha1_state);    // Calculate begin of data to be hashed    BeginBuffer = pSI->BeginMpqData;    // Create the digest    for (;;) {        ULONGLONG BytesRemaining;        DWORD dwToRead = MPQ_DIGEST_UNIT_SIZE;        // Check the number of bytes remaining        BytesRemaining = pSI->EndMpqData - BeginBuffer;        if (BytesRemaining < MPQ_DIGEST_UNIT_SIZE)            dwToRead = (DWORD)BytesRemaining;        if (dwToRead == 0)            break;        // Read the next chunk        if (!FileStream_Read(ha->pStream, &BeginBuffer, pbDigestBuffer, dwToRead)) {            FREEMEM(pbDigestBuffer);            return false;        }        // Pass the buffer to the hashing function        sha1_process(&sha1_state, pbDigestBuffer, dwToRead);        // Move pointers        BeginBuffer += dwToRead;    }    // Add all three known tails and generate three hashes    memcpy(&sha1_state_temp, &sha1_state, sizeof(hash_state));    sha1_done(&sha1_state_temp, sha1_tail0);    memcpy(&sha1_state_temp, &sha1_state, sizeof(hash_state));    AddTailToSha1(&sha1_state_temp, GetPlainFileName(ha->pStream->szFileName));    sha1_done(&sha1_state_temp, sha1_tail1);    memcpy(&sha1_state_temp, &sha1_state, sizeof(hash_state));    AddTailToSha1(&sha1_state_temp, "ARCHIVE");    sha1_done(&sha1_state_temp, sha1_tail2);    // Finalize the MD5 hash    FREEMEM(pbDigestBuffer);    return true;}
开发者ID:BinaryMuse,项目名称:StormLib,代码行数:58,


示例12: CopyHashTable

// Creates a copy of hash tablestatic TMPQHash * CopyHashTable(TMPQArchive * ha){    TMPQHash * pHashTableCopy = ALLOCMEM(TMPQHash, ha->pHeader->dwHashTableSize);    if(pHashTableCopy != NULL)        memcpy(pHashTableCopy, ha->pHashTable, sizeof(TMPQHash) * ha->pHeader->dwHashTableSize);    return pHashTableCopy;}
开发者ID:SparkoPro,项目名称:ghostnordicleague,代码行数:10,


示例13: SLm_RegisterModForce

// register mod which overrides internal packages -----------------------------//PRIVATEint SLm_RegisterModForce( char **modname ){	char *name = modname[ 0 ];	//NOTE:	// mod_names[] is the global storage for the current mod names,	// declared in CON_EXT.C	// If mod_names[ 0 ] != NULL, a mod is currently active	if ( mod_numnames >= MAX_REGISTERED_MODS ) {		return FALSE;	}	mod_names[ mod_numnames ] = (char *) ALLOCMEM( strlen( name ) + 1 );	if ( mod_names[ mod_numnames ] == NULL ) {		return FALSE;	}	strcpy( mod_names[ mod_numnames ], name );	// allocate memory for "name/name.dat" string	char *packagename = (char *) ALLOCMEM( strlen( name ) * 2 + 6 );	if ( packagename == NULL ) {		return FALSE;	}	strcpy( packagename, name );	strcat( packagename, "/" );	strcat( packagename, name );	strcat( packagename, ".dat" );	if ( !SYS_RegisterPackage( packagename, 0, name ) ) {		MSGOUT( "CLI error: package registration failed (%s)./n", name );		MSGOUT( "CLI error: continuing without package./n" );	}	mod_numnames++;	FREEMEM( packagename );	// set override flag	mod_override = TRUE;	return TRUE;}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:46,


示例14: ExecStartupScript

// exec startup script (usually boot.con, but also boot scripts of mods) ------//void ExecStartupScript( int echo ){	// exec startup command script	char *startupscript = NULL;	// start normal or mod boot scripts	if ( mod_numnames > 0 ) {		ASSERT( mod_names[ 0 ] != NULL );		// if mod doesn't override our own packages, execute our boot.con too		if ( !mod_override ) {			//startupscript = PlayDemo ? demo_script_name : boot_script_name;			if(TheServer->GetServerIsMaster()){				startupscript = boot_script_master_name;			} else {				startupscript = boot_script_name;			}			ExecConsoleFile( startupscript, echo );		}		// afterwards, exec <modname>/boot.con for each registered mod		for ( int curmod = 0; curmod < mod_numnames; curmod++ ) {			ASSERT( mod_names[ curmod ] != NULL );			startupscript = (char *) ALLOCMEM(				strlen( mod_names[ curmod ] ) + 1 + strlen( boot_script_name ) );			if ( startupscript == NULL ) {				OUTOFMEM( 0 );			}			strcpy( startupscript, mod_names[ curmod ] );			strcat( startupscript, "/" );			strcat( startupscript, boot_script_name );			// must be done to ensure the file can be found independently of			// whether it is read from a package or from a real directory			char *path = SYSs_ProcessPathString( startupscript );			ExecConsoleFile( path, echo );			FREEMEM( startupscript );			startupscript = NULL;		}	} else {		// if no mod is active, we just exec boot.con		//startupscript = PlayDemo ? demo_script_name : boot_script_name;		if(TheServer->GetServerIsMaster()){			startupscript = boot_script_master_name;		} else {			startupscript = boot_script_name;		}		ExecConsoleFile( startupscript, echo );	}}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:58,


示例15: VaporTrailInstantiate

// vapor trail constructor (class instantiation) ------------------------------//PRIVATEvoid VaporTrailInstantiate( CustomObject *base ){	ASSERT( base != NULL );	VaporTrail *vapor = (VaporTrail *) base;	// allocate memory for segments in one block	char *segmem = (char *) ALLOCMEM( ( sizeof( Vertex3 ) * 2 + sizeof( refframe_t ) ) * vapor->max_segments );	if ( segmem == NULL )		OUTOFMEM( "no mem for vapor trail." );	vapor->Trail_R	= (Vertex3 *) ( segmem );	vapor->Trail_L	= (Vertex3 *) ( segmem + sizeof( Vertex3 ) * vapor->max_segments );	vapor->alive	= (refframe_t *) ( segmem + sizeof( Vertex3 ) * vapor->max_segments * 2 );}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:16,


示例16: CON_RegisterUserCommand

// register a new user-defined command ----------------------------------------//int CON_RegisterUserCommand( user_command_s *regcom ){	//NOTE:	//CAVEAT:	// the supplied command string is not copied	// by this function. thus, the caller MUST ENSURE	// that this string is available indefinitely.	// (e.g., allocated statically.)	//NOTE:	// the commlen field need not be valid, it will be	// set by this function. (in the original struct!)	ASSERT( regcom != NULL );	ASSERT( regcom->command != NULL );	ASSERT( regcom->execute != NULL );	ASSERT( regcom->numparams >= 0 );	ASSERT( num_user_commands <= max_user_commands );	// expand table memory if already used up	if ( num_user_commands == max_user_commands ) {		// expand exponentially		int newtabsize = max_user_commands * 2;		// alloc new table		user_command_s *newlist = (user_command_s *) ALLOCMEM( sizeof( user_command_s ) * newtabsize );		if ( newlist == NULL ) {			ASSERT( 0 );			return FALSE;		}		// set new size		max_user_commands = newtabsize;		// move old table		memcpy( newlist, user_commands, sizeof( user_command_s ) * num_user_commands );		if ( user_commands != user_commands_default )			FREEMEM( user_commands );		user_commands = newlist;	}	// append new command	regcom->commlen = strlen( regcom->command );	ASSERT( num_user_commands < max_user_commands );	user_commands[ num_user_commands++ ] = *regcom;	return TRUE;}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:51,


示例17: SYS_AcquirePackageDemos

// acquire demos contained in package files -----------------------------------//int SYS_AcquirePackageDemos(){#ifdef PARSEC_CLIENT	// scan all registered packages	for ( unsigned int packid = 0; packid < (unsigned int)num_data_packages; packid++ ) {		// scan all items of this package		for ( unsigned int curit = 0; curit < package_numitems[ packid ]; curit++ ) {			// guard against overflow of registered demos			if ( num_registered_demos >= max_registered_demos )				break;			int demoid = num_registered_demos;			pfileinfo_s	*item = &package_items[ packid ][ curit ];			// extension is mandatory			long len = strlen( item->file ) - 4;//			ASSERT( ( len >= 0 ) && ( len <= COMMAND_NAME_ALLOC_LEN ) );			if ( len < 0 )				continue;			// check demo extension			if ( strcmp( item->file + len, CON_FILE_COMPILED_EXTENSION ) != 0 )				continue;			// store demo name			if ( registered_demo_names[ demoid ] != NULL ) {				FREEMEM( registered_demo_names[ demoid ] );				registered_demo_names[ demoid ] = NULL;			}			registered_demo_names[ demoid ] = (char *) ALLOCMEM( len + 1 );			if ( registered_demo_names[ demoid ] == NULL )				continue;			strncpy( registered_demo_names[ demoid ], item->file, len );			registered_demo_names[ demoid ][ len ] = 0;			// convert to lower-case			strlwr( registered_demo_names[ demoid ] );			num_registered_demos++;		}	}#endif // PARSEC_CLIENT	return TRUE;}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:48,


示例18: InitDemoTextCache

// cache demo text as bitmap or textures --------------------------------------//PRIVATEvoid InitDemoTextCache( int lineid ){	ASSERT(0);		ASSERT( (dword)lineid < DEMOTEXT_NUM_LINES );	// size of buffer for string blit	size_t bufsize = Screen_Width * Screen_BytesPerPixel * 80;	//NOTE:	// using Screen_Pitch instead of ( Screen_Width * Screen_BytesPerPixel )	// doesn't always work here because on a Voodoo3 Screen_Pitch will be set	// to 2048, as on all other Voodoos. this is too low for resolutions	// higher than 1024x768.	demotext_fontmem[ lineid ] = (char *) ALLOCMEM( bufsize );	if ( demotext_fontmem[ lineid ] == NULL )		OUTOFMEM( 0 );	memset( demotext_fontmem[ lineid ], 0, bufsize );	int charsetid = demotext_charset_id[ lineid ];	D_SetWStrContext( CharsetInfo[ charsetid ].charsetpointer,					  CharsetInfo[ charsetid ].geompointer,					  demotext_fontmem[ lineid ],					  CharsetInfo[ charsetid ].width,					  CharsetInfo[ charsetid ].height );	if ( demotext_capitals[ lineid ] ) {		strupr( demotext_text[ lineid ] );	} else {		strlwr( demotext_text[ lineid ] );	}	int swidth = D_GetPStringWidth( demotext_text[ lineid ] );	if ( swidth <= Screen_Width ) {//		D_WritePString( demotext_text[ lineid ], (Screen_Width-swidth)/2, 0 );	} else {		MSGOUT( "string too long." );	}	// split up bitmap into appropriately sized textures if necessary	if ( VidInfo_UseIterForDemoTexts ) {		CreateBitmapTextures( &demotext_fontmem[ lineid ] );	}}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:48,


示例19: ReadPalettes

// read palette files into buffer ---------------------------------------------//PRIVATEvoid ReadPalettes(){	// exit if nothing to read	if ( NumLoadedPalettes == 0 )		PANIC( "no palette defined." );	if ( ( PaletteMem = (char *) ALLOCMEM( PALETTE_SIZE * NumLoadedPalettes ) ) == NULL )		OUTOFMEM( no_palette_mem );	if ( display_info ) {		MSGPUT( "Loading palettes" );		if ( show_palettes_loaded ) {			MSGOUT( ":/n" );		} else {			MSGPUT( "..." );		}	}	// load all palettes	size_t readofs = 0;	for ( int pid = 0; pid < NumLoadedPalettes; pid++ ) {		if ( display_info && !show_palettes_loaded )			MSGPUT( "." );		FILE *fp = SYS_fopen( palette_fnames[ pid ], "rb" );		if ( fp == NULL )			FERROR( palette_not_found, palette_fnames[ pid ] );		if ( display_info && show_palettes_loaded ) {			MSGOUT( "loading /"%s/" (palette)/n", palette_fnames[ pid ] );		}		size_t bytesread = SYS_fread( PaletteMem + readofs, 1, PALETTE_SIZE, fp );		if ( bytesread != PALETTE_SIZE )			FERROR( palette_readerror, palette_fnames[ pid ] );		readofs += PALETTE_SIZE;		SYS_fclose( fp );	}	if ( display_info ) {		MSGOUT( "done./n" );	}}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:48,


示例20: WritePackageData

// write actual file data into output package ---------------------------------//PRIVATEint WritePackageData( FILE *fp, list_item_s *listitems, int numitems ){	ASSERT( fp != NULL );	ASSERT( listitems != NULL );	ASSERT( numitems > 0 );	for ( int curit = 0; curit < numitems; curit++ ) {		PrintfNoNL( "." );		FILE *itfp = fopen( listitems[ curit ].file, "rb" );		if ( itfp == NULL ) {			Err_Printf( "/ndata file /"%s/" not found: %s/n",					 listitems[ curit ].file, strerror( errno ) );			return FALSE;		}		char *filedata = (char *) ALLOCMEM( listitems[ curit ].flength );		if ( filedata == NULL ) {			fclose( itfp );			return FALSE;		}		size_t bytesread = fread( filedata, 1, listitems[ curit ].flength, itfp );		if ( bytesread != listitems[ curit ].flength ) {			FREEMEM( filedata );			fclose( itfp );			return FALSE;		}		size_t byteswritten = fwrite( filedata, 1, listitems[ curit ].flength, fp );		if ( byteswritten != listitems[ curit ].flength ) {			FREEMEM( filedata );			fclose( itfp );			return FALSE;		}		fclose( itfp );		FREEMEM( filedata );	}	return TRUE;}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:46,


示例21: ASSERT

// read sample after determining its format -----------------------------------//sample_s *SND_ReadSample( sampleinfo_s *pSampleInfo ){	ASSERT( pSampleInfo != NULL );	// determine sound type from extension	char *fext = SYSs_ScanToExtension( pSampleInfo->file );	sample_s *pSample = (sample_s *) ALLOCMEM(sizeof(sample_s));	pSample->format = SAMPLEFORMAT_INVALID;//	pSample->samplebuffer;	if ( stricmp( fext, snd_ext_wav ) == 0 ) {		pSample->format = SAMPLEFORMAT_WAV;		WAV_ReadSample(pSampleInfo,pSample);	}	return pSample;}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:21,


示例22: AllocPacketsChain

// allocate received packets chain (head node) --------------------------------//PRIVATEint AllocPacketsChain(){	ASSERT( ReceivedPacketsChain == NULL );	ReceivedPacketsChain = (PacketChainHead *) ALLOCMEM( sizeof( PacketChainHead ) );	if ( ReceivedPacketsChain == NULL ) {		if ( TextModeActive ) {			fprintf( stderr, pchain_alloc_error );			fprintf( stderr, net_game_unavail );		} else {			OUTOFMEM( 0 );		}		return FALSE;	}	ReceivedPacketsChain->nextblock   = NULL;	ReceivedPacketsChain->chainlength = 0;	return TRUE;}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:21,


示例23: RegisterShader

// register new shader --------------------------------------------------------//int RegisterShader( shader_s *shader ){	ASSERT( shader != NULL );	if ( num_registered_shaders >= MAX_NUM_REGISTERED_SHADERS )		return FALSE;	// name is mandatory	if ( shader->name == NULL )		return FALSE;	dword shaderid = num_registered_shaders;	// check for already registered shader of same name	if ( FetchShaderByName( shader->name, &shaderid ) != NULL ) {		if ( !AUX_ENABLE_SHADER_OVERLOADING ) {			return FALSE;		}	} else {		// allocate new shader name		char *name = (char *) ALLOCMEM( strlen( shader->name ) + 1 );		if ( name == NULL )			OUTOFMEM( 0 );		strcpy( name, shader->name );		ASSERT( registered_shaders[ shaderid ].name == NULL );		registered_shaders[ shaderid ].name = name;		num_registered_shaders++;	}	// store shader info	registered_shaders[ shaderid ].iter		 = shader->iter;	registered_shaders[ shaderid ].flags	 = shader->flags;	registered_shaders[ shaderid ].texanim	 = shader->texanim;	registered_shaders[ shaderid ].facecolor = shader->facecolor;	registered_shaders[ shaderid ].colanim	 = shader->colanim;	registered_shaders[ shaderid ].colflags	 = shader->colflags;	return TRUE;}
开发者ID:OpenParsec,项目名称:openparsec,代码行数:45,


示例24: build_common_binary_response_fields

static void build_common_binary_response_fields(struct request_state* req){	if (!req->bin_hdr_response)	{		req->bin_hdr_response = (struct memcache_hdr_res*)			ALLOCMEM(MEMCACHED_PKT_HDR_RES_LEN, GFP_KERNEL);	}	req->bin_hdr_response->magic = MEMCACHED_MAGIC_RES;	req->bin_hdr_response->opcode = req->cmd;	req->bin_hdr_response->len_key = 0L;	req->bin_hdr_response->len_extras = 0L;	req->bin_hdr_response->datatype = 0L;	req->bin_hdr_response->opaque = 0L;	req->bin_hdr_response->cas = 0L;	req->bin_hdr_response->status = 0L; // overridden later if necessary	req->bin_hdr_response->len_body = 0L;	return;}
开发者ID:jonathanmarvens,项目名称:unbuckle,代码行数:19,


示例25: ALLOCMEM

/************* * DESCRIPTION:   read the points * INPUT:         data     handler data *                cn       iff context node * OUTPUT:        error string *************/static char *ReadPoints(HANDLER_DATA *data, struct ContextNode *cn){	int count;	// get point count (each point has a size of 12 bytes)	count = (cn->cn_Size)/sizeof(VECTOR);	// Allocate memory	data->pointcount = count;	data->points = ALLOCMEM(VECTOR, count);	if (!data->points)		return errors[ERR_MEM];	// Read points	if(!ReadFloat(data->iff, (float*)data->points, count*3))		return errors[ERR_LWOBFILE];	return NULL;}
开发者ID:Kalamatee,项目名称:RayStorm,代码行数:25,


示例26: DEMO_BinaryReadDemo

// read binary demo file as one huge block ------------------------------------//PRIVATEint DEMO_BinaryReadDemo( FILE *fp, int infomsgs, int errormsgs ){	ASSERT( fp != NULL );	ASSERT( demo_data == NULL );	// get file size	if ( SYS_fseek( fp, 0, SEEK_END ) != 0 ) {		return FALSE;	}	size_t demosize = SYS_ftell( fp );	if ( SYS_fseek( fp, 0, SEEK_SET ) != 0 ) {		return FALSE;	}	// check for demo header and parse it if present	size_t headersize = DEMO_ParseDemoHeader( fp, -1, infomsgs );	if ( demosize >= headersize ) {		demosize -= headersize;	}	if ( demosize == 0 ) {		return FALSE;	}	// allocate mem for demo data	demo_data = (char *) ALLOCMEM( demosize );	if ( demo_data == NULL ) {		if ( errormsgs )			CON_AddLine( "no mem for demo replay." );		return FALSE;	}	// read entire file into single memory block	if ( SYS_fread( demo_data, 1, demosize, fp ) != demosize ) {		if ( errormsgs )			CON_AddLine( "error reading demo file." );		return FALSE;	}	return TRUE;}
开发者ID:ppiecuch,项目名称:openparsec,代码行数:43,


示例27: ub_core_run

int ub_core_run(void){	int res;		struct request_state* req = (struct request_state*) 		ALLOCMEM(sizeof(struct request_state), GFP_KERNEL);#ifdef __KERNEL__	allow_signal(SIGKILL | SIGSTOP);#endif	if (!req#ifdef __KERNEL__		|| ksize(req) < sizeof(struct request_state)#endif		)		return -ENOMEM;	memset(req, 0, sizeof(struct request_state));	if ((res = udpserver_start(req)) < 0)	{#ifdef DEBUG		PRINTARGS(#ifdef __KERNEL__		KERN_ERR #endif		"Something went wrong starting the UDP server %d/n", res);#endif		FREEMEM(req);		return res;	}	res = process_slowpath(req);	udpserver_exit();	if (req)	{		FREEMEM(req);		req = NULL;	}	return res;}
开发者ID:jonathanmarvens,项目名称:unbuckle,代码行数:41,


示例28: fr_create

FRAME          *fr_create(int entries, int size){	FRAME          *tab;	if (size < sizeof(char **))		size = sizeof(char **);	/* ensure size for free list */	if ((tab = ALLOCMEM(FRAME, 1)) == 0) {		return 0;	}	tab->nentry = entries;	tab->nsize = size;	if ((tab->frbuf = MALLOCMEM(entries * size)) == 0) {		FREEMEM(tab);		return 0;	}	init_list(tab);	tab->next = 0;		/* continuation block */	return tab;}
开发者ID:vocho,项目名称:openqnx,代码行数:21,


示例29: ApplyMpqPatch_COPY

static int ApplyMpqPatch_COPY(    TMPQFile * hf,    TPatchHeader * pPatchHeader){    LPBYTE pbNewFileData;    DWORD cbNewFileData;    // Allocate space for new file data    cbNewFileData = pPatchHeader->dwXfrmBlockSize - SIZE_OF_XFRM_HEADER;    pbNewFileData = ALLOCMEM(BYTE, cbNewFileData);    if(pbNewFileData == NULL)        return ERROR_NOT_ENOUGH_MEMORY;    // Copy the patch data as-is    memcpy(pbNewFileData, (LPBYTE)pPatchHeader + sizeof(TPatchHeader), cbNewFileData);    // Free the old file data    FREEMEM(hf->pbFileData);    // Put the new file data there    hf->pbFileData = pbNewFileData;    hf->cbFileData = cbNewFileData;    return ERROR_SUCCESS;}
开发者ID:milleniumcore,项目名称:CactusEMU,代码行数:24,


示例30: SFileCreateArchive

bool WINAPI SFileCreateArchive(const char * szMpqName, DWORD dwFlags, DWORD dwMaxFileCount, HANDLE * phMpq){    TFileStream * pStream = NULL;           // File stream    TMPQArchive * ha = NULL;                // MPQ archive handle    ULONGLONG MpqPos = 0;                   // Position of MPQ header in the file    HANDLE hMpq = NULL;    USHORT wFormatVersion = MPQ_FORMAT_VERSION_1;    DWORD dwBlockTableSize = 0;             // Initial block table size    DWORD dwHashTableSize = 0;    int nError = ERROR_SUCCESS;    // Check the parameters, if they are valid    if(szMpqName == NULL || *szMpqName == 0 || phMpq == NULL)    {        SetLastError(ERROR_INVALID_PARAMETER);        return false;    }    // One time initialization of MPQ cryptography    InitializeMpqCryptography();    // We verify if the file already exists and if it's a MPQ archive.    // If yes, we won't allow to overwrite it.    if(SFileOpenArchive(szMpqName, 0, dwFlags, &hMpq))    {        SFileCloseArchive(hMpq);        SetLastError(ERROR_ALREADY_EXISTS);        return false;    }    //    // At this point, we have to create the archive.    // - If the file exists, convert it to MPQ archive.    // - If the file doesn't exist, create new empty file    //    pStream = FileStream_OpenFile(szMpqName, true);    if(pStream == NULL)    {        pStream = FileStream_CreateFile(szMpqName);        if(pStream == NULL)            return false;    }    // Decide what format to use    wFormatVersion = (USHORT)((dwFlags & MPQ_CREATE_ARCHIVE_VMASK) >> 16);    if(wFormatVersion > MPQ_FORMAT_VERSION_4)    {        SetLastError(ERROR_INVALID_PARAMETER);        return false;    }    // Increment the maximum amount of files to have space    // for listfile and attributes file    if(dwFlags & MPQ_CREATE_ATTRIBUTES)        dwMaxFileCount++;    dwMaxFileCount++;    // If file count is not zero, initialize the hash table size    dwHashTableSize = GetHashTableSizeForFileCount(dwMaxFileCount);    // Retrieve the file size and round it up to 0x200 bytes    FileStream_GetSize(pStream, MpqPos);    MpqPos = (MpqPos + 0x1FF) & (ULONGLONG)0xFFFFFFFFFFFFFE00ULL;    if(!FileStream_SetSize(pStream, MpqPos))        nError = GetLastError();#ifdef _DEBUG        // Debug code, used for testing StormLib//  dwBlockTableSize = dwHashTableSize * 2;#endif    // Create the archive handle    if(nError == ERROR_SUCCESS)    {        if((ha = ALLOCMEM(TMPQArchive, 1)) == NULL)            nError = ERROR_NOT_ENOUGH_MEMORY;    }    // Fill the MPQ archive handle structure    if(nError == ERROR_SUCCESS)    {        memset(ha, 0, sizeof(TMPQArchive));        ha->pStream         = pStream;        ha->dwSectorSize    = (wFormatVersion >= MPQ_FORMAT_VERSION_3) ? 0x4000 : 0x1000;        ha->UserDataPos     = MpqPos;        ha->MpqPos          = MpqPos;        ha->pHeader         = (TMPQHeader *)ha->HeaderData;        ha->dwMaxFileCount  = dwMaxFileCount;        ha->dwFileTableSize = 0;        ha->dwFileFlags1    = MPQ_FILE_ENCRYPTED | MPQ_FILE_COMPRESS |  MPQ_FILE_REPLACEEXISTING;        ha->dwFileFlags2    = MPQ_FILE_ENCRYPTED | MPQ_FILE_COMPRESS |  MPQ_FILE_REPLACEEXISTING;        ha->dwFlags         = 0;        // Setup the attributes        if(dwFlags & MPQ_CREATE_ATTRIBUTES)            ha->dwAttrFlags = MPQ_ATTRIBUTE_CRC32 | MPQ_ATTRIBUTE_FILETIME | MPQ_ATTRIBUTE_MD5;        pStream = NULL;    }//.........这里部分代码省略.........
开发者ID:mewbak,项目名称:sau,代码行数:101,



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


C++ ALLOC_ARRAY函数代码示例
C++ ALLOCA函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。