Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
 void reset( int maxSize ) {
     l = 0;
     if ( maxSize && size > maxSize ) {
         al.Free(data);
         data = (char*)al.Malloc(maxSize);
         assert(data);
         size = maxSize;
     }
 }
Ejemplo n.º 4
0
 _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;
 }