示例#1
0
		bool RedBlackTree<Key, Data>::killNode(RedBlackNode<Key, Data> * z)
		{
			RedBlackNode<Key, Data> *x, *y;

			if (!valid(z->left) || !valid(z->right)) {
				/* y has a null node as a child */
				y = z;
			} else {
				/* find tree successor with a null node as a child */
				y = z->right;

				while (valid(y->left))
					y = y->left;
			}

			/* x is y's only child */
			if (valid(y->left))
				x = y->left;
			else
				x = y->right;

			/* remove y from the parent chain */
			if (valid(x)) x->parent = y->parent;

			if (valid(y->parent)) {
				if (y == y->parent->left)
					y->parent->left = x;
				else
					y->parent->right = x;
			} else
				rootNode = x;

			if (y != z) {
				Dealloc(z->id);
				z->id = Duplicate(y->id);
				z->data = y->data;
			} else {
				Dealloc(y->id);
			}

			if (y->color == BLACK)
				deleteFixup(x);

			m_cachedSize--;

			y->left = NULL;
			y->right = NULL;
			delete y;

			return true;
		}
示例#2
0
		bool SplayTree<Key, Data>::killNode(SplayNode<Key, Data> * z)
		{
			SplayNode<Key, Data> *x, *y;

			if (z->left == NULL || z->right == NULL) {
				/* y has a NULL node as a child */
				y = z;
			} else {
				/* find tree successor with a NULL node as a child */
				y = z->right;

				while (y->left != NULL)
					y = y->left;
			}

			/* x is y's only child */
			if (y->left != NULL)
				x = y->left;
			else
				x = y->right;

			/* remove y from the parent chain */
			if (x) x->parent = y->parent;

			if (y->parent) {
				if (y == y->parent->left)
					y->parent->left = x;
				else
					y->parent->right = x;
			} else
				root = x;

			if (y != z) {
				Dealloc(z->id);
				z->id = Duplicate(y->id);
				z->data = y->data;
			} else {
				Dealloc(y->id);
			}

			m_size--;

			y->left = NULL;
			y->right = NULL;
			delete y;

			return true;
		}
示例#3
0
static void
Decomp_dealloc(compobject *self)
{
    if (self->is_initialised)
        inflateEnd(&self->zst);
    Dealloc(self);
}
bool CLnFaktTab::Init( long n)
// Vytvori tabulku logaritmu faktorialu od 0 do n
// Pri nedostatku pameti vraci FALSE
{
	if ( !m_LnFaktTab ||
		 n > m_n)
	{
		Dealloc();

		m_LnFaktTab= new FAKTVALUE[n+ 1];
		if ( !m_LnFaktTab) return false;

		m_n= n;

		m_LnFaktTab[0]= 0;

		long i;

		for (i= 1; i <= n; i++) m_LnFaktTab[i]= m_LnFaktTab[i-1]+ log((double) i);
			// ln( n!) == ln(1)+ ln(2)+ ...+ ln(n)
			// ln( n!) == ln((n-1)!)+ ln( n)
	}

	return true;
}
示例#5
0
		void RedBlackTree<Key, Data>::killAll(RedBlackNode<Key, Data> *rec)
		{
			if (!valid(rec)) {
				return;
			}

			/* First kill our subnodes: */
			if (valid(rec->left))
				killAll(rec->left);

			if (valid(rec->right))
				killAll(rec->right);

			if (valid(rec->parent)) {                /* We're not root. */
				if (rec->parent->left == rec)
					rec->parent->left = nullNode;
				else
					rec->parent->right = nullNode;
			}

			Dealloc(rec->id);
			rec->left = NULL;
			rec->right = NULL;
			delete rec;
		}
示例#6
0
		void HashTable<Data>::empty()
		{
			for (size_t i = 0; i < m_size; ++i) {
				if (m_keys[i] == (char*)-1) m_keys[i] = NULL;
				Dealloc(m_keys[i]);
			}

			memset(m_keys, 0, sizeof(char *) * m_size);
			memset(m_data, 0, sizeof(Data) * m_size);
		}
示例#7
0
		bool HashTable<Data>::erase(const char *_key)
		{
			size_t index = findIndex(_key);
			if (index != (size_t)-1) {
				Dealloc(m_keys[index]);
				m_keys[index] = (char*)-1;
				m_slotsFree++;
				return true;
			}
			return false;
		}
示例#8
0
static ULONG Release(void* instance)
{
	BonjourUserEventsPlugin* plugin = (BonjourUserEventsPlugin*)instance;

	if (plugin->_refCount != 0)
		--plugin->_refCount;
	
	if (plugin->_refCount == 0)
	{
		Dealloc(instance);
		return 0;
	}
	
	return plugin->_refCount;
} 
示例#9
0
	MeasureAllocDeallocTime(ElapsedTimeRec& timeRec, std::size_t blockSize, int preAlloc, int maxAlloc) :
		m_pPool		(NULL)
	{
		std::vector<char*> ptrs(maxAlloc);
		{
			Poco::Stopwatch sw_total;
			sw_total.start();
			{	// initialize
				Poco::Stopwatch sw_init;
				sw_init.start();
				Init(blockSize, preAlloc, maxAlloc);
				sw_init.stop();
				timeRec.timeInit = (1000.0 * sw_init.elapsed()) / sw_init.resolution();
			}
			for(std::size_t loop=0; loop<kNumLoop; ++loop)
			{
				{	// allocate
					Poco::Stopwatch sw_alloc;
					sw_alloc.start();
					for(int i=0; i<maxAlloc; ++i)
					{
						ptrs[i] = Alloc(blockSize);
					}
					sw_alloc.stop();
					timeRec.timeAlloc[loop] = (1000.0 * sw_alloc.elapsed()) / sw_alloc.resolution();
				}
				{	// deallocate
					Poco::Stopwatch sw_dealloc;
					sw_dealloc.start();
					for(int i=0; i<maxAlloc; ++i)
					{
						Dealloc(ptrs[i]);
					}
					sw_dealloc.stop();
					timeRec.timeDealloc[loop] = (1000.0 * sw_dealloc.elapsed()) / sw_dealloc.resolution();
				}
			}
			{	// cleanup
				Poco::Stopwatch sw_cleanup;
				sw_cleanup.start();
				Cleanup();
				sw_cleanup.stop();
				timeRec.timeCleanup = (1000.0 * sw_cleanup.elapsed()) / sw_cleanup.resolution();
			}
			sw_total.stop();
			timeRec.timeTotal = (1000.0 * sw_total.elapsed()) / sw_total.resolution();
		}
	}
示例#10
0
///////////////////////////////////////
// Deallocate the Hydra's pointers
///////////////////////////////////////
void  HydraClass::ZapHydra(void)
{
  WORD  wNdx;

  if (achBankName != NULL)
  {
    delete [] achBankName;
    achBankName = NULL;
  }
  
  HydraVersion.wMajor = HydraVersion.wMinor = 0;
  if (pPHdr != NULL)
  {
    if (pPHdr != NULL) Dealloc((VOIDPTR)pPHdr);
    if (pPBag != NULL) Dealloc((VOIDPTR)pPBag);
    if (pPGen != NULL) Dealloc((VOIDPTR)pPGen);
    if (pPMod != NULL) Dealloc((VOIDPTR)pPMod);
    if (pInst != NULL) Dealloc((VOIDPTR)pInst);
    if (pIBag != NULL) Dealloc((VOIDPTR)pIBag);
    if (pIGen != NULL) Dealloc((VOIDPTR)pIGen);
    if (pIMod != NULL) Dealloc((VOIDPTR)pIMod);
    if (pSHdr != NULL) Dealloc((VOIDPTR)pSHdr);
  }

  pPHdr        = NULL;
  pPBag        = NULL;
  pPGen        = NULL;
  pPMod        = NULL;
  pInst        = NULL;
  pIBag        = NULL;
  pIGen        = NULL;
  pIMod        = NULL;
  pSHdr        = NULL;

  for (wNdx = 0; wNdx < SF_DATASTRUCTS; wNdx++)
  {
    awStructSize[wNdx] = 0;
  }
}
示例#11
0
		bool SplayTree<Key, Data>::insert(Key const &key, Data const &x)
		{
			static SplayNode<Key, Data> *newNode = NULL;

			if (newNode == NULL)
				newNode = new SplayNode<Key, Data>;
			else
				Dealloc(newNode->id);

			newNode->id = Duplicate(key);
			newNode->data = x;
			newNode->parent = newNode->right = newNode->left = NULL;

			if (root == NULL) {
				newNode->left = newNode->right = NULL;
				root = newNode;
			} else {
				splay(key, root);
				if (Compare(key, root->id) < 0)	{
					newNode->left = root->left;
					if (newNode->left)
						newNode->left->parent = newNode;

					newNode->right = root;
					root->parent = newNode;
					root->left = NULL;
					root = newNode;
				} else
				if (Compare(root->id, key) < 0)	{
					newNode->right = root->right;
					if (newNode->right)
						newNode->right->parent = newNode;

					newNode->left = root;
					root->parent = newNode;
					root->right = NULL;
					root = newNode;
				} else
					return false;
			}

			m_size++;
			newNode = NULL;               /* So next insert will call new */
			return true;
		}
示例#12
0
bool
GMPSharedMemManager::MgrDeallocShmem(GMPSharedMem::GMPMemoryClasses aClass, ipc::Shmem& aMem)
{
  mData->CheckThread();

  size_t size = aMem.Size<uint8_t>();
  size_t total = 0;

  // XXX Bug NNNNNNN Until we put better guards on ipc::shmem, verify we
  // weren't fed an shmem we already had.
  for (uint32_t i = 0; i < GetGmpFreelist(aClass).Length(); i++) {
    if (NS_WARN_IF(aMem == GetGmpFreelist(aClass)[i])) {
      // Safest to crash in this case; should never happen in normal
      // operation.
      MOZ_CRASH("Deallocating Shmem we already have in our cache!");
      //return true;
    }
  }

  // XXX This works; there are better pool algorithms.  We need to avoid
  // "falling off a cliff" with too low a number
  if (GetGmpFreelist(aClass).Length() > 10) {
    Dealloc(GetGmpFreelist(aClass)[0]);
    GetGmpFreelist(aClass).RemoveElementAt(0);
    // The allocation numbers will be fubar on the Child!
    mData->mGmpAllocated[aClass]--;
  }
  for (uint32_t i = 0; i < GetGmpFreelist(aClass).Length(); i++) {
    MOZ_ASSERT(GetGmpFreelist(aClass)[i].IsWritable());
    total += GetGmpFreelist(aClass)[i].Size<uint8_t>();
    if (size < GetGmpFreelist(aClass)[i].Size<uint8_t>()) {
      GetGmpFreelist(aClass).InsertElementAt(i, aMem);
      return true;
    }
  }
  GetGmpFreelist(aClass).AppendElement(aMem);

  return true;
}
示例#13
0
void Coord::Set(unsigned int width, unsigned int height)
{
	Coord::width = width;
	Coord::height = height;
	Coord::count = width * height;
	unsigned int maxSize = static_cast<unsigned int>( pow(2.0,static_cast<double>(8*sizeof(char))) / 2 - 1);
	if( std::max(width,height) > maxSize)
	{
		char str[256];
		sprintf_s(str,sizeof(str),"Playing board too big, max size is %u",maxSize);
		throw _Exception(str);
	}

	Dealloc();
	distance = new char[count * count];
	direction = new Direction[count * count];
	neighbourList = new Crd[count * (MAX_NEIGHBOURS + 1)];
	influencyList = new Crd[count* directionCount  *(MAX_INFLUENCES_DIRECTION  + 1)];
	SetDistanceDirection();
	SetDirectionShift();
	SetNeighbourList();
	SetInfluencyList();
}
CLnFaktTab::~CLnFaktTab()
{
	Dealloc();
}
示例#15
0
GamePad_SDL::~GamePad_SDL() {
  g_pErr->DFI("GamePad_SDL::~GamePad_SDL", 0L, 1);
  Dealloc();
  g_pErr->DFO("GamePad_SDL::~GamePad_SDL", 0L, 1);
}
示例#16
0
	AX_RETURN_NULL
	AX_FORCEINLINE tElement *Dealloc( tElement *p )
	{
		return ( tElement * )Dealloc( ( void * )p );
	}
示例#17
0
 Server::~Server()
 {
   Dealloc();
   delete Net;
 }
示例#18
0
BYTEPTR sfReader::Allocate(SHORT        iHydraSymbol,
			   SHORT        iMemStructSize,
			   SHORT        iFileStructSize,
			   DWORD        dwChkSize,
	                   HydraClass   *hf)
//*************************************************************************
//
// Parameters: iHydraSymbol:    The SoundFont Data Structure symbol
//
//             iMemStructSize:  The size in bytes of memory required by
//                              a HydraFont head, (ie sizeof(whatever)
//
//             iFileStructSize: The size in bytes occupied in a file
//                              by a HydraFont head, 
//
//  Systems with different byte boundries will allocate memory from
//  the heap differently. Thus when allocating and accessing memory,
//  the iMemStructSize tells use the padded size of memory if applicable.
//
//***************************************************************************
{

sfVersion  *fileVersion; 
DWORD      rcnt; 
BYTEPTR    pData = NULL; 

WORD       mono =        monoSample; 


  tRIFF.SwapBytes(&mono);

  fileVersion = (sfVersion*)(infoCkValues[Ifil]);

  if ( iHydraSymbol == sampHdr )  {
     
    fileVersion = (sfVersion*)(infoCkValues[Ifil] );

    // get the count of how many sampleHdr elements in the array...

    hf->awStructSize[iHydraSymbol] = 
           (WORD) (dwChkSize /(DWORD) SAMPHDRV2_SIZE); // 46 bytes/element

    // now allocate our in memory representation... based on elements
    // times the inmemory size, (ie sizeof from the invocation ) 

    if ((pData = (BYTEPTR) Alloc((DWORD) hf->awStructSize[iHydraSymbol] * 
				       iMemStructSize)) == 0)   {
      SetError(EHC_ALLOCATE_PMEM_ERROR); 
      return (pData);
    }
    Memset( pData,0,hf->awStructSize[iHydraSymbol]*iMemStructSize);

    // now for however many elements we have lets do the reading...

    //
    // Element for element read of data, to serve as an example of a possible
    // issue with cross platform code. See comments below.
    //
    for(WORD curHdr=0; curHdr < hf->awStructSize[iHydraSymbol]; curHdr++) { 

        rcnt = 0; 

        rcnt += tRIFF.RIFFRead((VOIDPTR)
                               &((sfSampleHdr*)pData)[curHdr].achSampleName, 
				             1, SAMPLENAMESIZE);

        rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].dwStart,       
	                                     1, sizeof(DWORD));

        rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].dwEnd, 
	 	 		             1, sizeof(DWORD));

        rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].dwStartloop, 
 					     1, sizeof(DWORD));

        rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].dwEndloop,  
 					     1, sizeof(DWORD));

        rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].dwSampleRate,
                                               1, sizeof(DWORD));

	rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].byOriginalKey,
					       1, sizeof(BYTE));

	rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].chFineCorrection,
					       1, sizeof(CHAR));

	rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].wSampleLink,
                                               1, sizeof(WORD));

        rcnt += tRIFF.RIFFRead( &((sfSampleHdr*)pData)[curHdr].sfSampleType,
                                               1, sizeof(WORD));

        if( rcnt != SAMPHDRV2_SIZE) { 
#ifdef DEBUG
        qDebug()<<"%Allocate-E-error reading sampleHdr V2 ";
#endif
          Dealloc(pData);
          SetError(SF_INVALIDBANK);
          return (NULL);
        }
     }// end for all elements
  }  // do sampleHdr reading, 

  else { 

    hf->awStructSize[iHydraSymbol] = (WORD) (dwChkSize /
					  (DWORD) iFileStructSize);
    if ((pData = (BYTEPTR) Alloc((DWORD) hf->awStructSize[iHydraSymbol] * 
				       iMemStructSize)) == 0)
    {
      SetError(EHC_ALLOCATE_PMEM_ERROR); 
      return (pData);
    }

    DWORD dwNdx;


    for (WORD wNdx= 0; wNdx< hf->awStructSize[iHydraSymbol]; wNdx++)
    {
      dwNdx = (DWORD)((DWORD)wNdx* (DWORD)iMemStructSize);

      //
      // NOTE: ANSI makes NO specification about how elements in a 
      //       data structure is ALIGNED within that data structure.
      //       Although a byte-for-byte copy from the file image into
      //       the memory image of the Data Structure like what is happening
      //       below works with many major commercial compilers for Intel
      //       Motorola, and Sparc microprocessors under DOS, Windows,
      //       Mac System 7, SunOS 4.3, and other major operating systems there 
      //       are no guarantees it will work EVERYWHERE. 
      //
      //       This READ may need to be re-written to stuff all ELEMENTS
      //       of each Data Structure INDIVIDUALLY to guarantee alignment!
      //       (See how the SampleHeader reads are done above)
      //
      //       On the OTHER hand...
      //       A possible OPTIMIZATION is that if you are on a 16 bit 
      //       bounded system, AND you are NOT reading the defined
      //       INST and SHDR structures (iHydraSymbol == inst OR sampHdr)
      //       you can do large reads spanning multiple data structures.
      //       and get all data in one shot...
      //
      //       IE Kill the 'for' loop and do:
      //           tRIFF.RIFFRead((VOIDPTR)pData, 1, 
      //                          hf->awStructSize[iHydraSymbol] * 
      //                          iMemStructSize);
      //
      //       To do this for ALL data structures, remove the RefCount and
      //       sampleLoaded fields from the definitons of the inst and 
      //       sampHdr structs FIRST!
      //
      if (0 == tRIFF.RIFFRead((VOIDPTR)(&pData[dwNdx]),
			      1,
			      iFileStructSize))
      {
        Dealloc(pData);
        pData = NULL;
        SetError(EHC_READFILEERROR); 
	break;
      }
    }  // end to read all elements
  } // end to new else do normal thing.

  return (pData);

}// end Allocate