Logo Search packages:      
Sourcecode: libpodofo version File versions  Download package

void PoDoFo::PdfRefCountedBuffer::ReallyDetach ( size_t  lExtraLen ) [private]

Called by Detach() to do the work if action is actually required.

See also:
Detach

Definition at line 54 of file PdfRefCountedBuffer.cpp.

References DerefBuffer(), PoDoFo::ePdfError_OutOfMemory, GetBuffer(), GetSize(), PoDoFo::PDF_MAX(), PODOFO_RAISE_ERROR, and PODOFO_RAISE_LOGIC_IF.

Referenced by Detach().

{
    PODOFO_RAISE_LOGIC_IF( m_pBuffer && m_pBuffer->m_lRefCount == 1, "Use Detach() rather than calling ReallyDetach() directly." )

    size_t lSize                 = m_pBuffer->m_lBufferSize + lExtraLen; 
    TRefCountedBuffer* pBuffer = new TRefCountedBuffer();
    pBuffer->m_lRefCount       = 1;

    pBuffer->m_bOnHeap = (lSize > TRefCountedBuffer::INTERNAL_BUFSIZE);
    if ( pBuffer->m_bOnHeap )
        pBuffer->m_pHeapBuffer  = static_cast<char*>(malloc( sizeof(char)*lSize ));
    else
        pBuffer->m_pHeapBuffer = 0;
    pBuffer->m_lBufferSize     = PDF_MAX( lSize, static_cast<size_t>(+TRefCountedBuffer::INTERNAL_BUFSIZE) );
    pBuffer->m_bPossesion      = true;

    if( pBuffer->m_bOnHeap && !pBuffer->m_pHeapBuffer ) 
    {
        delete pBuffer;
        pBuffer = NULL;

        PODOFO_RAISE_ERROR( ePdfError_OutOfMemory );
    }

    memcpy( pBuffer->GetRealBuffer(), this->GetBuffer(), this->GetSize() );
    // Detaching the buffer should have NO visible effect to clients, so the
    // visible size must not change.
    pBuffer->m_lVisibleSize    = m_pBuffer->m_lVisibleSize;

    // Now that we've copied the data, release our claim on the old buffer,
    // deleting it if needed, and link up the new one.
    DerefBuffer();
    m_pBuffer = pBuffer;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index