Beispiel #1
0
/* allocates a memory block */
void * hb_gcAllocRaw( HB_SIZE nSize, const HB_GC_FUNCS * pFuncs )
{
   PHB_GARBAGE pAlloc;

   pAlloc = HB_GARBAGE_NEW( nSize );
   pAlloc->pFuncs = pFuncs;
   pAlloc->locked = 0;
   pAlloc->used   = s_uUsedFlag;

   HB_GC_LOCK();
#ifdef HB_GC_AUTO
   if( s_ulBlocks > s_ulBlocksCheck )
   {
      HB_GC_UNLOCK();
      hb_gcCollectAll( HB_TRUE );
      HB_GC_LOCK();
      pAlloc->used = s_uUsedFlag;
   }
   HB_GC_AUTO_INC();
#endif
   hb_gcLink( &s_pCurrBlock, pAlloc );
   HB_GC_UNLOCK();

   return HB_BLOCK_PTR( pAlloc );        /* hide the internal data */
}
Beispiel #2
0
/* allocates a memory block */
void * hb_gcAllocate( HB_SIZE nSize, const HB_GC_FUNCS * pFuncs )
{
   PHB_GARBAGE pAlloc;

   pAlloc = HB_GARBAGE_NEW( nSize );
   pAlloc->pFuncs = pFuncs;
   pAlloc->locked = 1;
   pAlloc->used   = s_uUsedFlag;
   HB_GC_LOCK();
   hb_gcLink( &s_pLockedBlock, pAlloc );
   HB_GC_UNLOCK();

   return HB_BLOCK_PTR( pAlloc );        /* hide the internal data */
}
Beispiel #3
0
HB_ITEM_PTR hb_gcGripGet( HB_ITEM_PTR pOrigin )
{
   HB_GARBAGE_PTR pAlloc;

   #ifdef GC_RECYCLE
      HB_CRITICAL_LOCK( hb_garbageAllocMutex );
      if( s_pAvailableItems )
      {
         pAlloc = s_pAvailableItems;
         hb_gcUnlink( &s_pAvailableItems, s_pAvailableItems );
         HB_CRITICAL_UNLOCK( hb_garbageAllocMutex );
      }
      else
      {
         HB_CRITICAL_UNLOCK( hb_garbageAllocMutex );
         pAlloc = ( HB_GARBAGE_PTR ) hb_xgrab( sizeof( HB_ITEM ) + sizeof( HB_GARBAGE ) );
      }
   #else
      pAlloc = HB_GARBAGE_NEW( sizeof( HB_ITEM ) + sizeof( HB_GARBAGE ) );
   #endif

   if( pAlloc )
   {
      HB_ITEM_PTR pItem = ( HB_ITEM_PTR )( pAlloc + 1 );


      pAlloc->pFunc  = hb_gcGripRelease;
      pAlloc->locked = 1;
      pAlloc->used   = s_uUsedFlag;

      pItem->type = HB_IT_NIL;
      if( pOrigin )
      {
         hb_itemCopy( pItem, pOrigin );
      }

      HB_THREAD_GUARD( hb_garbageAllocMutex, hb_gcLink( &s_pLockedBlock, pAlloc ) );
      return pItem;
   }
   else
   {
      return NULL;
   }
}
Beispiel #4
0
/* allocates a memory block */
void * hb_gcAlloc( ULONG ulSize, HB_GARBAGE_FUNC_PTR pCleanupFunc )
{
   HB_GARBAGE_PTR pAlloc;

   #ifdef GC_RECYCLE
      HB_CRITICAL_LOCK( hb_garbageAllocMutex );
      if( s_pAvailableBaseArrays && ulSize == sizeof( HB_BASEARRAY ) )
      {
         pAlloc = s_pAvailableBaseArrays;
         hb_gcUnlink( &s_pAvailableBaseArrays, s_pAvailableBaseArrays );
         HB_CRITICAL_UNLOCK( hb_garbageAllocMutex );
      }
      else
      {
         HB_CRITICAL_UNLOCK( hb_garbageAllocMutex );
         pAlloc = ( HB_GARBAGE_PTR ) hb_xgrab( ulSize + sizeof( HB_GARBAGE ) );
      }
   #else
      pAlloc = HB_GARBAGE_NEW( ulSize + sizeof( HB_GARBAGE ) );
   #endif

   if( pAlloc )
   {
      pAlloc->pFunc  = pCleanupFunc;
      pAlloc->ulHolders = 0;
      pAlloc->locked = 0;
      pAlloc->used   = s_uUsedFlag;

      HB_CRITICAL_LOCK( hb_garbageAllocMutex );
      s_uAllocated++;
      s_uAllocatedCnt++;
      hb_gcLink( &s_pCurrBlock, pAlloc );
      HB_CRITICAL_UNLOCK( hb_garbageAllocMutex );

      HB_TRACE( HB_TR_DEBUG, ( "hb_gcAlloc %p in %p", pAlloc + 1, pAlloc ) );

      return (void *)( pAlloc + 1 );   /* hide the internal data */
   }
   else
   {
      return NULL;
   }
}
Beispiel #5
0
PHB_ITEM hb_gcGripGet( PHB_ITEM pOrigin )
{
   PHB_GARBAGE pAlloc = HB_GARBAGE_NEW( sizeof( HB_ITEM ) );
   PHB_ITEM pItem = ( PHB_ITEM ) HB_BLOCK_PTR( pAlloc );

   pAlloc->pFuncs = &s_gcGripFuncs;
   pAlloc->locked = 1;
   pAlloc->used   = s_uUsedFlag;

   pItem->type = HB_IT_NIL;

   HB_GC_LOCK();
   hb_gcLink( &s_pLockedBlock, pAlloc );
   HB_GC_UNLOCK();

   if( pOrigin )
      hb_itemCopy( pItem, pOrigin );

   return pItem;
}