本文整理匯總了C++中ALLOCMEM函數的典型用法代碼示例。如果您正苦於以下問題:C++ ALLOCMEM函數的具體用法?C++ ALLOCMEM怎麽用?C++ ALLOCMEM使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ALLOCMEM函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
示例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 > 4GB
static 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;
}
示例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;
}
示例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;
}
示例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++;
}
示例6: CreatePackage
// create data package --------------------------------------------------------
//
PRIVATE
int 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;
}
示例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;
}
示例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;
}
示例9: VaporTrailRegisterCustomType
// register object type for vapor trail ---------------------------------------
//
PRIVATE
void 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 );
}
示例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;
}
示例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;
}
示例12: CopyHashTable
// Creates a copy of hash table
static 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;
}
示例13: SLm_RegisterModForce
// register mod which overrides internal packages -----------------------------
//
PRIVATE
int 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;
}
示例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 );
}
}
示例15: VaporTrailInstantiate
// vapor trail constructor (class instantiation) ------------------------------
//
PRIVATE
void 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 );
}