本文整理汇总了C++中Allocator::Malloc方法的典型用法代码示例。如果您正苦于以下问题:C++ Allocator::Malloc方法的具体用法?C++ Allocator::Malloc怎么用?C++ Allocator::Malloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Allocator
的用法示例。
在下文中一共展示了Allocator::Malloc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestAllocator
void TestAllocator(Allocator& a) {
EXPECT_TRUE(a.Malloc(0) == 0);
uint8_t* p = (uint8_t*)a.Malloc(100);
EXPECT_TRUE(p != 0);
for (size_t i = 0; i < 100; i++)
p[i] = (uint8_t)i;
// Expand
uint8_t* q = (uint8_t*)a.Realloc(p, 100, 200);
EXPECT_TRUE(q != 0);
for (size_t i = 0; i < 100; i++)
EXPECT_EQ(i, q[i]);
for (size_t i = 100; i < 200; i++)
q[i] = (uint8_t)i;
// Shrink
uint8_t *r = (uint8_t*)a.Realloc(q, 200, 150);
EXPECT_TRUE(r != 0);
for (size_t i = 0; i < 150; i++)
EXPECT_EQ(i, r[i]);
Allocator::Free(r);
// Realloc to zero size
EXPECT_TRUE(a.Realloc(a.Malloc(1), 1, 0) == 0);
}
示例2: InitJob
bool TransportHandlerFile::InitJob(TransportInfo* pTInfo, bool& bStateComplete)
{
using namespace EA::WebKit;
// We return true if we feel we can handle the job.
FileSystem* pFS = GetFileSystem();
if(pFS != NULL)
{
Allocator* pAllocator = GetAllocator();
FileInfo* pFileInfo = new(pAllocator->Malloc(sizeof(FileInfo), 0, "EAWebKit/TransportHandlerFile")) FileInfo;
pTInfo->mTransportHandlerData = (uintptr_t)pFileInfo;
bStateComplete = true;
#ifdef EA_DEBUG
mJobCount++;
#endif
sFileOpenJobCount++;
return true;
}
return false;
}
示例3: reset
void reset( int maxSize ) {
l = 0;
if ( maxSize && size > maxSize ) {
al.Free(data);
data = (char*)al.Malloc(maxSize);
assert(data);
size = maxSize;
}
}
示例4: size
_BufBuilder(int initsize = 512) : size(initsize) {
if ( size > 0 ) {
data = (char *) al.Malloc(size);
assert(data); // "out of memory BufBuilder");
}
else {
data = 0;
}
l = 0;
}