Appends the chain with the first nBytes nB (void*) buffer of given size. This operation makes no assumptions about buffer content and so the operation is not null terminated.

Return TypeFunction nameArguments
uint32_thzChain::Append(const void*,uint32_t,)

Declared in file: hzChain.h
Defined in file : hzChain.cpp

Function Logic:

0:START 1:unknown 2:Return nBytes 3:unknown 4:mx mx 5:unknown 6:mx 7:mx 8:curBlk 9:unknown 10:items 11:i 12:unknown 13:unknown 14:newBlk items items curBlk mx ZBLKSIZE 15:nCan 16:unknown 17:nBytes 18:nCan 19:items curBlk i mx nWritten 20:Return nWritten

Function body:

uint32_t hzChain::Append (const void* vpStr)uint32_t nBytes, 
{
   //  Appends the chain with the first nBytes nB (void*) buffer of given size. This operation makes no assumptions about buffer content and so the operation is
   //  not null terminated.
   //  
   //  Arguments: 1) vpStr The buffer address as void*
   //     2) nBytes The number of bytes from the buffer to append to the chain
   //  
   //  Returns: Number of bytes added
   _hzfunc("hzChain::Append(1)") ;
   _zblk*      curBlk ;            //  Working block pointer
   _zblk*      newBlk ;            //  Working block pointer
   const char* i ;                 //  Input iterator
   uint32_t    nCan ;              //  Max number of bytes that can be written to current block
   uint32_t    nWritten = 0;       //  Limiter
   if (!nBytes)
       return nBytes ;
   //  If nothing in chain, create the first block
   if (!mx)
       { mx = new _chain() ; mx->m_Test = mx ; }
   if (!mx->m_Begin)
       mx->m_Begin = mx->m_End = _zblk_alloc() ;
   curBlk = (_zblk*) mx->m_End ;
   if (!curBlk)
       hzexit(E_MEMORY, "Chain %p has no end block\n", this) ;
   i = (char*) vpStr ;
   for (; nWritten < nBytes ;)
   {
       if (curBlk->m_nUsage == ZBLKSIZE)
       {
           //  Out of space - make new block
           newBlk = _zblk_alloc() ;
           newBlk->Prev(curBlk) ;
           curBlk->Next(newBlk) ;
           mx->m_End = curBlk = newBlk ;
       }
       nCan = ZBLKSIZE - curBlk->m_nUsage ;
       if ((nWritten + nCan) > nBytes)
           nCan = nBytes - nWritten ;
       //  Add bytes to current block
       //  threadLog("Appending %u bytes to posn %u\n", nCan, curBlk->m_nUsage) ;
       memcpy(curBlk->m_Data + curBlk->m_nUsage, i, nCan) ;
       curBlk->m_nUsage += nCan ;
       i += nCan ;
       mx->m_nSize += nCan ;
       nWritten += nCan ;
   }
   return nWritten ;
}