void* NorlsAllocator::_AllocNonZero(size_t& sz)
{
    AssertIfFalse((size_t)nextFree % sizeof(void*) == 0);
    AssertIfFalse((size_t)limitFree % sizeof(void*) == 0);

    void * p = nextFree;
    if (sz == 0 && p == NULL)
    {
        sz = 1;
    }

    size_t roundSize = VBMath::RoundUpAllocSize(sz);
    size_t available = limitFree - nextFree;

    if ( available < roundSize )
    {
        AllocNewPage(sz);
    }

    p = nextFree;
    nextFree += roundSize; // this shouldn't overflow because we got the memory for the request (we would have thrown in AllocNewPage() otherwise)

    MakeCurrentPageWriteableInternal();

    AssertIfFalse((size_t)nextFree % sizeof(void*) == 0);
    AssertIfFalse((size_t)limitFree % sizeof(void*) == 0);
    AssertIfFalse((size_t)p % sizeof(void*) == 0);

#if NRLSTRACK
    m_nTotalAllocated += roundSize;
    m_dwAllocThreadId  = 0;
#endif NRLSTRACK

    sz = roundSize;
#if NRLSTRACK
    VSASSERT(m_dwAllocThreadId == 0," NorlsAlloc: only 1 thread allowed at a time");
    m_dwAllocThreadId = GetCurrentThreadId();
    m_nSeqNo+=1;


#if NRLSTRACK_GETSTACKS
    //
    NrlsHeapData  *pdata =
        (NrlsHeapData *) VsDebugAllocInternal(TrackingHeapToUse(),
                HEAP_ZERO_MEMORY | HEAP_GENERATE_EXCEPTIONS,
                (sizeof (NrlsHeapData )), __FILE__, __LINE__, INSTANCE_GLOBAL, NULL);

    pdata->m_ptrNextBlock = m_pLastBlock; // linked list of allocations: point to prior one
    pdata->m_size = sz;  // record the size
    pdata->m_data = p;  // record the actual allocation
    m_pLastBlock = pdata; // track the most recent one
#endif NRLSTRACK_GETSTACKS
#endif NRLSTRACK
    return p;
}
Ejemplo n.º 2
0
/*
 * Allocate from the heap. Memory WILL be zeroed.
 */
void * MEMHEAP::_AllocZero(size_t sz
#ifdef DEBUG
, PCSTR pszFile, UINT iLine
#endif
)
{
    ASSERT(heap != 0);

#ifdef DEBUG
    // Use the actual internal alloc function so we can pass in the file/line values
    void * p = VsDebugAllocInternal(heap, HEAP_ZERO_MEMORY, sz, pszFile, iLine, INSTANCE_GLOBAL, NULL);
#else
    void * p = VSHeapAllocZero(heap, sz);
#endif
    if (p == 0)
        host->NoMemory();


    return p;
}
Ejemplo n.º 3
0
void * _cdecl operator new [](size_t cbSize)
{
#if DEBUG && _X86_
// if you get a leak report from VSAssert you'll get a line like:
//          d:\dd\vsleditor\src\vb\language\include\vbheap.cpp(10189270):	0x0DF2E258, bytes = 8, nAlloc=133514, TID=0x1104
// Break into the debugger. Take the # in parens, put it in Watch window: turn on hex display->it shows addr of caller
// Go to disassembly, put the address in the Address bar hit enter. Bingo: you're at the caller that didn't free!
// see http://blogs.msdn.com/calvin_hsia/archive/2009/01/19/9341632.aspx
    UINT *EbpRegister ;
    _asm { mov EbpRegister, ebp};
    UINT CallerAddr = *(((size_t *)EbpRegister)+1) ;

//    CallerAddr -=  (size_t)g_hinstDll;

    void *mem = VsDebugAllocInternal(g_vbCommonHeap, HEAP_ZERO_MEMORY | HEAP_GENERATE_EXCEPTIONS, (cbSize), __FILE__,CallerAddr , INSTANCE_GLOBAL, NULL);
#else
    void *mem = VBAlloc(cbSize);
#endif
    return mem;
}