本文整理汇总了C++中M_Malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ M_Malloc函数的具体用法?C++ M_Malloc怎么用?C++ M_Malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了M_Malloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static FDoubleProd *NewDoubleProd (double val)
{
FDoubleProd *prod = (FDoubleProd *)M_Malloc (sizeof(FDoubleProd));
prod->Type = PROD_Double;
prod->Value = val;
return prod;
}
示例2: InitializeActorInfo
// This is used by DECORATE to assign ActorInfos to internal classes
void PClass::InitializeActorInfo ()
{
Symbols.SetParentTable (&ParentClass->Symbols);
Defaults = (BYTE *)M_Malloc(Size);
if (ParentClass->Defaults != NULL)
{
memcpy (Defaults, ParentClass->Defaults, ParentClass->Size);
if (Size > ParentClass->Size)
{
memset (Defaults + ParentClass->Size, 0, Size - ParentClass->Size);
}
}
else
{
memset (Defaults, 0, Size);
}
FActorInfo *info = ActorInfo = new FActorInfo;
info->Class = this;
info->GameFilter = GAME_Any;
info->SpawnID = 0;
info->DoomEdNum = -1;
info->OwnedStates = NULL;
info->NumOwnedStates = 0;
info->Replacement = NULL;
info->Replacee = NULL;
info->StateList = NULL;
info->DamageFactors = NULL;
info->PainChances = NULL;
info->PainFlashes = NULL;
info->ColorSets = NULL;
info->ScoreOnDeath = 0;
m_RuntimeActors.Push (this);
}
示例3: CreateStateLabelList
static FStateLabels * CreateStateLabelList(TArray<FStateDefine> & statelist)
{
// First delete all empty labels from the list
for (int i=statelist.Size()-1;i>=0;i--)
{
if (statelist[i].Label == NAME_None || (statelist[i].State == NULL && statelist[i].Children.Size() == 0))
{
statelist.Delete(i);
}
}
int count=statelist.Size();
if (count == 0) return NULL;
FStateLabels * list = (FStateLabels*)M_Malloc(sizeof(FStateLabels)+(count-1)*sizeof(FStateLabel));
list->NumLabels = count;
for (int i=0;i<count;i++)
{
list->Labels[i].Label = statelist[i].Label;
list->Labels[i].State = statelist[i].State;
list->Labels[i].Children = CreateStateLabelList(statelist[i].Children);
}
qsort(list->Labels, count, sizeof(FStateLabel), labelcmp);
return list;
}
示例4: FindString
void FStringTable::SetString (const char *name, const char *newString)
{
StringEntry **pentry, *oentry;
FindString (name, pentry, oentry);
size_t newlen = strlen (newString);
size_t namelen = strlen (name);
// Create a new string entry
StringEntry *entry = (StringEntry *)M_Malloc (sizeof(*entry) + newlen + namelen);
strcpy (entry->String, newString);
strcpy (entry->Name = entry->String + newlen + 1, name);
entry->PassNum = 0;
// If this is a new string, insert it. Otherwise, replace the old one.
if (oentry == NULL)
{
entry->Next = *pentry;
*pentry = entry;
}
else
{
*pentry = entry;
entry->Next = oentry->Next;
M_Free (oentry);
}
}
示例5: DENG_ASSERT
ddstring_t *Str_Prepend(ddstring_t *str, char const *prepend)
{
char *copied;
size_t incoming;
DENG_ASSERT(str);
DENG_ASSERT(prepend);
if(!str || !prepend) return str;
incoming = strlen(prepend);
if(incoming == 0)
return str;
copied = M_Malloc(incoming);
memcpy(copied, prepend, incoming);
allocateString(str, str->length + incoming, true);
memmove(str->str + incoming, str->str, str->length + 1);
memcpy(str->str, copied, incoming);
str->length += incoming;
M_Free(copied);
return str;
}
示例6: M_Malloc
Rect *Rect_New(void)
{
Rect *r = M_Malloc(sizeof *r);
r->origin = Point2_New();
r->size = Size2_New();
return r;
}
示例7: ModuleInstall_Stddev
//----初始化标准输入模块-------------------------------------------------------
//功能: 初始化标准输入模块,执行初始化后,可以创建输入设备。
//参数: 无
//返回: true = 成功,false= 失败.
//-----------------------------------------------------------------------------
bool_t ModuleInstall_Stddev(ptu32_t para)
{
static struct tagStdinDeviceRsc root;
tg_pStdinInputMsgQ = Stddev_CreatInputMsgQ(10,"StdInDev");
if(tg_pStdinInputMsgQ == NULL)
return false;
g_ptStdinDevice = M_Malloc(gc_u32CfgStdinDeviceLimit
* sizeof(struct tagStdinDeviceRsc),0);
if(g_ptStdinDevice == NULL)
{
Stddev_DeleteInputMsgQ(tg_pStdinInputMsgQ);
return false;
}
s_ptStdinDeviceRscTree = (struct tagStdinDeviceRsc *)
Rsc_AddTree(&root.stdin_device_node,
sizeof(struct tagStdinDeviceRsc),RSC_STDIN_OUT,"stdin input device");
//初始化泛设备控制块内存池
g_ptStdinDevicePool = Mb_CreatePool((void*)g_ptStdinDevice,
gc_u32CfgStdinDeviceLimit,
sizeof(struct tagStdinDeviceRsc),
2,10,
"输入设备控制块内存池");
Stddev_SetFocusDefault(tg_pStdinInputMsgQ);
return true;
}
示例8: sizeof
FMemArena::Block *FMemArena::AddBlock(size_t size)
{
Block *mem, **last;
size += sizeof(Block); // Account for header size
// Search for a free block to use
for (last = &FreeBlocks, mem = FreeBlocks; mem != NULL; last = &mem->NextBlock, mem = mem->NextBlock)
{
if ((BYTE *)mem->Limit - (BYTE *)mem >= (ptrdiff_t)size)
{
*last = mem->NextBlock;
break;
}
}
if (mem == NULL)
{
// Allocate a new block
if (size < BlockSize)
{
size = BlockSize;
}
else
{ // Stick some free space at the end so we can use this block for
// other things.
size += BlockSize/2;
}
mem = (Block *)M_Malloc(size);
mem->Limit = (BYTE *)mem + size;
}
mem->Reset();
mem->NextBlock = TopBlock;
TopBlock = mem;
return mem;
}
示例9: Alloc
void FRemapTable::Alloc(int count)
{
Remap = (BYTE *)M_Malloc(count*sizeof(*Remap) + count*sizeof(*Palette));
assert (Remap != NULL);
Palette = (PalEntry *)(Remap + count*(sizeof(*Remap)));
Native = NULL;
NumEntries = count;
}
示例10: LOG_AS
size_t Zip::readLump(int lumpIdx, uint8_t* buffer, size_t startOffset,
size_t length, bool tryCache)
{
LOG_AS("Zip::readLump");
ZipFile const& file = reinterpret_cast<ZipFile&>(lump(lumpIdx));
LOG_TRACE("\"%s:%s\" (%u bytes%s) [%u +%u]")
<< de::NativePath(composePath()).pretty()
<< de::NativePath(file.composePath()).pretty()
<< (unsigned long) file.size()
<< (file.isCompressed()? ", compressed" : "")
<< startOffset
<< length;
// Try to avoid a file system read by checking for a cached copy.
if(tryCache)
{
uint8_t const* data = d->lumpCache? d->lumpCache->data(lumpIdx) : 0;
LOG_TRACE("Cache %s on #%i") << (data? "hit" : "miss") << lumpIdx;
if(data)
{
size_t readBytes = MIN_OF(file.size(), length);
memcpy(buffer, data + startOffset, readBytes);
return readBytes;
}
}
size_t readBytes;
if(!startOffset && length == file.size())
{
// Read it straight to the caller's data buffer.
readBytes = d->bufferLump(file, buffer);
}
else
{
// Allocate a temporary buffer and read the whole lump into it(!).
uint8_t* lumpData = (uint8_t*) M_Malloc(file.size());
if(!lumpData) throw Error("Zip::readLumpSection", QString("Failed on allocation of %1 bytes for work buffer").arg(file.size()));
if(d->bufferLump(file, lumpData))
{
readBytes = MIN_OF(file.size(), length);
memcpy(buffer, lumpData + startOffset, readBytes);
}
else
{
readBytes = 0;
}
M_Free(lumpData);
}
/// @todo Do not check the read length here.
if(readBytes < MIN_OF(file.size(), length))
throw Error("Zip::readLumpSection", QString("Only read %1 of %2 bytes of lump #%3").arg(readBytes).arg(length).arg(lumpIdx));
return readBytes;
}
示例11: memset
SaveInfo *SaveInfo_New(void)
{
SaveInfo *info = (SaveInfo *)M_Malloc(sizeof *info);
Str_Init(&info->name);
info->gameId = 0;
memset(&info->header, 0, sizeof(info->header));
return info;
}
示例12: sizeof
// =============================================================================
// 功能:新增SPI总线结点到SPI总线类型结点,并初始化tagSPI_CB控制块结构体
// 参数:NewSPIParam,新增总线参数,参数说明详细请参照tagSPI_Param结构体
// 返回:返回建立的资源结点指针,失败时返回NULL
// =============================================================================
struct tagSPI_CB *SPI_BusAdd(struct tagSPI_Param *NewSPIParam)
{
struct tagSPI_CB *NewSPI;
if(NULL == NewSPIParam)
goto exit_from_param;
//避免重复建立同名的SPI总线
if(NULL != Rsc_SearchSon(&s_SPIBusType,NewSPIParam->BusName))
goto exit_from_readd;
NewSPI = (struct tagSPI_CB *)M_Malloc(sizeof(struct tagSPI_CB),0);
if(NewSPI == NULL)
goto exit_from_malloc;
//将总线结点挂接到总线类型结点的子结点
Rsc_AddSon(&s_SPIBusType,&NewSPI->SPI_BusNode,
sizeof(struct tagSPI_CB),RSC_SPIBUS,NewSPIParam->BusName);
if(&NewSPI->SPI_BusNode == NULL)
goto exit_from_add_node;
//创建总线信号量和阻塞信号量
NewSPI->SPI_BusSemp= Lock_SempCreate(1,1,CN_SEMP_BLOCK_FIFO,"spi bus semp");
if(NewSPI->SPI_BusSemp== NULL)
goto exit_from_spi_bus_semp;
NewSPI->SPI_BlockSemp = Lock_SempCreate(1,0,CN_SEMP_BLOCK_FIFO,"spi block semp");
if(NewSPI->SPI_BlockSemp== NULL)
goto exit_from_spi_buf_semp;
//tagSPI_CB控制块初始化
NewSPI->SpecificFlag = NewSPIParam->SpecificFlag;
NewSPI->pTransferTxRx = NewSPIParam->pTransferTxRx;
NewSPI->pCsActive = NewSPIParam->pCsActive;
NewSPI->pCsInActive = NewSPIParam->pCsInActive;
NewSPI->pBusCtrl = NewSPIParam->pBusCtrl;
NewSPI->pTransferPoll = NewSPIParam->pTransferPoll;
//缓冲区初始化
NewSPI->SPI_Buf.pBuf = NewSPIParam->SPIBuf;
NewSPI->SPI_Buf.MaxLen = NewSPIParam->SPIBufLen;
NewSPI->SPI_Buf.Offset = 0;
printk("%s Added Succeeded!\r\n",NewSPIParam->BusName);
return NewSPI;
exit_from_spi_buf_semp:
Lock_SempDelete(NewSPI->SPI_BusSemp);
exit_from_spi_bus_semp:
Rsc_DelNode(&NewSPI->SPI_BusNode);
exit_from_add_node:
free(NewSPI);
exit_from_malloc:
exit_from_readd:
exit_from_param:
return NULL;
}
示例13: sizeof
void FTextureManager::AddComplexAnim (FTextureID picnum, const TArray<FAnimDef::FAnimFrame> &frames)
{
FAnimDef *anim = (FAnimDef *)M_Malloc (sizeof(FAnimDef) + (frames.Size()-1) * sizeof(frames[0]));
anim->BasePic = picnum;
anim->NumFrames = frames.Size();
anim->CurFrame = 0;
anim->AnimType = FAnimDef::ANIM_DiscreteFrames;
anim->SwitchTime = 0;
memcpy (&anim->Frames[0], &frames[0], frames.Size() * sizeof(frames[0]));
AddAnim (anim);
}
示例14: R_ClearDrawSegs
//
// R_ClearDrawSegs
//
void R_ClearDrawSegs (void)
{
if (drawsegs == NULL)
{
MaxDrawSegs = 256; // [RH] Default. Increased as needed.
firstdrawseg = drawsegs = (drawseg_t *)M_Malloc (MaxDrawSegs * sizeof(drawseg_t));
}
FirstInterestingDrawseg = 0;
InterestingDrawsegs.Clear ();
ds_p = drawsegs;
}
示例15: Printf
void FTextureManager::InitSwitchList ()
{
const BITFIELD texflags = TEXMAN_Overridable | TEXMAN_TryAny;
int lump = Wads.CheckNumForName ("SWITCHES");
if (lump != -1)
{
FMemLump lumpdata = Wads.ReadLump (lump);
const char *alphSwitchList = (const char *)lumpdata.GetMem();
const char *list_p;
FSwitchDef *def1, *def2;
for (list_p = alphSwitchList; list_p[18] || list_p[19]; list_p += 20)
{
// [RH] Check for switches that aren't really switches
if (stricmp (list_p, list_p+9) == 0)
{
Printf ("Switch %s in SWITCHES has the same 'on' state\n", list_p);
continue;
}
// [RH] Skip this switch if its textures can't be found.
if (CheckForTexture (list_p /* .name1 */, FTexture::TEX_Wall, texflags).Exists() &&
CheckForTexture (list_p + 9 /* .name2 */, FTexture::TEX_Wall, texflags).Exists())
{
def1 = (FSwitchDef *)M_Malloc (sizeof(FSwitchDef));
def2 = (FSwitchDef *)M_Malloc (sizeof(FSwitchDef));
def1->PreTexture = def2->frames[0].Texture = CheckForTexture (list_p /* .name1 */, FTexture::TEX_Wall, texflags);
def2->PreTexture = def1->frames[0].Texture = CheckForTexture (list_p + 9, FTexture::TEX_Wall, texflags);
def1->Sound = def2->Sound = 0;
def1->NumFrames = def2->NumFrames = 1;
def1->frames[0].TimeMin = def2->frames[0].TimeMin = 0;
def1->frames[0].TimeRnd = def2->frames[0].TimeRnd = 0;
AddSwitchPair(def1, def2);
}
}
}
mSwitchDefs.ShrinkToFit ();
qsort (&mSwitchDefs[0], mSwitchDefs.Size(), sizeof(FSwitchDef *), SortSwitchDefs);
}