当前位置: 首页>>代码示例>>C++>>正文


C++ Allocator类代码示例

本文整理汇总了C++中Allocator的典型用法代码示例。如果您正苦于以下问题:C++ Allocator类的具体用法?C++ Allocator怎么用?C++ Allocator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Allocator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char **argv)
{
   bool check = true;
   Allocator allocator;

   for ( int  n = 0; n < TIMES; n++ ) {
      for ( unsigned int i = 0; i < (sizeof( sizes )/sizeof(int)); i++ ) {

         int *ptr = (int *) allocator.allocate( sizes[i] * sizeof(int) );
         if ( ptr == NULL ) check = false;

         for ( int j = 0; j < sizes[i]; j++ ) ptr[j] = CHECK_VALUE; // INI
         for ( int j = 0; j < sizes[i]; j++ ) ptr[j]++; // INC
         for ( int j = 0; j < sizes[i]; j++ ) ptr[j]--; // DEC

         // Check result
         for ( int j = 0; j < sizes[i]; j++ ) {
            if ( ptr[j] != CHECK_VALUE ) exit(-1);
         }

         Allocator::deallocate( ptr );
      }
   }

   if (check) { return 0; } else { return -1; }
}
开发者ID:robbriggs,项目名称:masters-project-nanosxx,代码行数:26,代码来源:allocator_01.cpp

示例2: Disconnect

bool TransportHandlerFile::ShutdownJob(TransportInfo* pTInfo, bool& bStateComplete)
{
    if(pTInfo != NULL && pTInfo->mTransportHandlerData)
    {
        Disconnect(pTInfo, bStateComplete);

        FileInfo*  pFileInfo  = (FileInfo*)pTInfo->mTransportHandlerData;
        Allocator* pAllocator = GetAllocator();

        pFileInfo->~FileInfo();
        pAllocator->Free(pFileInfo, sizeof(FileInfo));

        pTInfo->mTransportHandlerData = 0;
        sFileOpenJobCount--;

        #ifdef EA_DEBUG
            mJobCount--;
        #endif
    
    }
    if(sFileOpenJobCount <= 0)
        RemoveFileDownloadBuffer();

    bStateComplete = true;
    return true;
}
开发者ID:Gin-Rye,项目名称:duibrowser,代码行数:26,代码来源:EAWebKitTransport.cpp

示例3: getJobLoggerLine

int SimLauncher::getJobLoggerLine(DCSimulator &sim, Allocator &alloc)
{
    
    std::string buffer;
    if (!std::getline(jobfile, buffer)){
        LOG_WARNING << "Could not read line from jobfile. We should NOT have reached"
                    << " this point in the code.";
        return -1;
    }
    VLOG_1 << "Job line is " << buffer ;
    int jobId = alloc.parseNewJob(sim, buffer);
    if (jobId == 0){
        // In off-line mode, this function is not the one signaling the end of
        // execution (exit only signals end of file).
        // In this case we go back to the beginning of the file again and restore
        // the initial allocation
        LOG_INFO << "Reached end-of-file. Will go back to the beginning";
        jobfile.clear();
        jobfile.seekg(0, std::ios::beg);
        VLOG_2 << "Resetting room parameters";
        DCParser::addRoomParams(xmlConfigFile, sim);
        VLOG_2 << "Resetting allocation";
        DCParser::addWorkload(xmlConfigFile, sim);
        VLOG_2 << "Seeking new job (first line)";
        // JOSELE: noLog=true;
        if (!std::getline(jobfile, buffer)){
            LOG_WARNING << "Could not read job file!";
            return -1;
        }
        jobId = alloc.parseNewJob(sim, buffer);
    }
    return jobId;
}
开发者ID:greendisc,项目名称:devs-slide,代码行数:33,代码来源:sim-launcher.cpp

示例4: expand

			void expand()
			{
				size_t size = (this->mask + 1) << 1;
				size_t mask = size - 1;

				Table table = allocator.allocate(size);
				
				if(!Allocator::null_references)
					for(size_t i = 0; i < size; ++i)
						table[i] = T::invalid_value();
				
				V *end = this->table + (this->mask + 1);
				
				for(V *slot = this->table; slot != end; ++slot)
				{
					V entry = *slot;

					while(T::valid_value(entry))
					{
						T::verify_value(entry);

						V next = T::get_value_next(entry);
						
						store(table, mask, T::get_key(entry), entry);
						
						entry = next;
					}
				}

				allocator.free(this->table);

				this->mask = mask;
				this->table = table;
			}
开发者ID:Zoxc,项目名称:Prelude,代码行数:34,代码来源:HashTable.hpp

示例5: xmalloc

/// Reallocates a memory block previously allocated with xalloc.
///	@param[in] ptr - a pointer to a block created with xalloc.
///	@param[in] size - the client requested block size to create.
extern "C" void *xrealloc(void *oldMem, size_t size)
{
	if (oldMem == 0)
		return xmalloc(size);

	if (size == 0) 
	{
		xfree(oldMem);
		return 0;
	}
	else 
	{
		// Create a new memory block
		void* newMem = xmalloc(size);
		if (newMem != 0) 
		{
			// Get the original allocator instance from the old memory block
			Allocator* oldAllocator = get_block_allocator(oldMem);
			size_t oldSize = oldAllocator->GetBlockSize() - sizeof(Allocator*);

			// Copy the bytes from the old memory block into the new (as much as will fit)
			memcpy(newMem, oldMem, (oldSize < size) ? oldSize : size);

			// Free the old memory block
			xfree(oldMem);

			// Return the client pointer to the new memory block
			return newMem;
		}
		return 0;
	}
}
开发者ID:IonutCava,项目名称:trunk,代码行数:35,代码来源:xallocator.cpp

示例6: GetFileSystem

bool TransportHandlerFile::InitJob(TransportInfo* pTInfo, bool& bStateComplete)
{
    using namespace EA::WebKit;

    // We return true if we feel we can handle the job.
    FileSystem* pFS = GetFileSystem();

    if(pFS != NULL)
    {
        Allocator* pAllocator = GetAllocator();
        FileInfo*  pFileInfo  = new(pAllocator->Malloc(sizeof(FileInfo), 0, "EAWebKit/TransportHandlerFile")) FileInfo; 

        pTInfo->mTransportHandlerData = (uintptr_t)pFileInfo;
        bStateComplete = true;

        #ifdef EA_DEBUG
            mJobCount++;
        #endif

        sFileOpenJobCount++;

        return true;
    }

    return false;
}
开发者ID:Gin-Rye,项目名称:duibrowser,代码行数:26,代码来源:EAWebKitTransport.cpp

示例7: CL_nssDistPointsToCssm

void CL_nssDistPointsToCssm(
	const NSS_CRLDistributionPoints	&nssObj,
	CE_CRLDistPointsSyntax			&cdsaObj,
	SecNssCoder 					&coder,	// for temp decoding
	Allocator						&alloc)
{
	memset(&cdsaObj, 0, sizeof(cdsaObj));
	unsigned numPoints = clNssArraySize((const void **)nssObj.distPoints);
	if(numPoints == 0) {
		return;
	}
	
	unsigned len = sizeof(CE_CRLDistributionPoint) * numPoints;
	cdsaObj.distPoints = (CE_CRLDistributionPoint *)alloc.malloc(len);
	memset(cdsaObj.distPoints, 0, len);
	cdsaObj.numDistPoints = numPoints;

	for(unsigned dex=0; dex<numPoints; dex++) {
		CE_CRLDistributionPoint &cpoint = cdsaObj.distPoints[dex];
		NSS_DistributionPoint &npoint = *(nssObj.distPoints[dex]);
	
		/* All three fields are optional */
		if(npoint.distPointName != NULL) {
			/* Drop in a CE_DistributionPointName */
			CE_DistributionPointName *cname = 
				(CE_DistributionPointName *)alloc.malloc(
					sizeof(CE_DistributionPointName));
			memset(cname, 0, sizeof(*cname));
			cpoint.distPointName = cname;
			
			/*
			 * This one is currently still encoded; we have to peek
			 * at its tag and decode accordingly.
			 */
			CL_decodeDistributionPointName(*npoint.distPointName,
				*cname, coder, alloc);
		}

		if(npoint.reasons.Data != NULL) {
			/* careful, it's a bit string */
			if(npoint.reasons.Length > 8) {
				clErrorLog("***CL_nssDistPointsToCssm: Malformed reasons\n");
				CssmError::throwMe(CSSMERR_CL_UNKNOWN_FORMAT);
			}
			cpoint.reasonsPresent = CSSM_TRUE;
			if(npoint.reasons.Length != 0) {
				cpoint.reasons = npoint.reasons.Data[0];
			}
		}
		
		if(npoint.crlIssuer.names != NULL) {
			/* Cook up a new CE_GeneralNames */
			cpoint.crlIssuer = 
				(CE_GeneralNames *)alloc.malloc(sizeof(CE_GeneralNames));
			CL_nssGeneralNamesToCssm(npoint.crlIssuer, *cpoint.crlIssuer,
				coder, alloc);
		}
	}
}
开发者ID:Apple-FOSS-Mirror,项目名称:Security,代码行数:59,代码来源:clNssUtils.cpp

示例8: main

int main( int argc, char* argv[] ) {
	srand( time( NULL ) );

	Allocator a = Allocator( POOLSIZE, NCLIENTS );
	a.start();

	a.join();
}
开发者ID:jreese,项目名称:rit,代码行数:8,代码来源:main.cpp

示例9: memmove

Allocator::Allocator(const Allocator &other)
:m_chunk({0,nullptr})
,m_size(0)
,m_mem(nullptr)
{
    this->Alloc(other.GetSize());
    memmove(this->GetPtr(), other.GetPtr(), other.GetSize());
}
开发者ID:Luweimy,项目名称:Torch,代码行数:8,代码来源:torch-allocator.cpp

示例10: Stack

 explicit Stack(int n) : capacity_(n), index_(0)
   {
     Allocator alloc;
     data_ = alloc.allocate(capacity_);
     for (int i = 0; i < capacity_; ++i) {
       alloc.construct(data_ + i);
     }
   }
开发者ID:LoliGothick,项目名称:2nd,代码行数:8,代码来源:05_alias_templates.cpp

示例11: cache

        /*!
         * \brief Primary constructor.
         *
         * Constructs an empty cache object and sets a maximum size for it. It is the only way to set size for a cache and it can't be changed later.
         * You could also  pass optional comparator object, compatible with Compare.
         *
         * \param <size> Maximum number of entries, allowed in the cache.
         * \param <comp> Comparator object, compatible with Compare type. Defaults to Compare()
         *
         */
        explicit cache(const size_type size, const Compare& comp = Compare()) {
            this->_storage=storageType(comp, Allocator<pair<const Key, Data> >());
            this->_maxEntries=size;
            this->_currEntries=0;

            policy_type localPolicy(size);
            this->_policy = policyAlloc.allocate(1);
            policyAlloc.construct(this->_policy,localPolicy);
        }
开发者ID:akashihi,项目名称:stlcache,代码行数:19,代码来源:stlcache.hpp

示例12: unload

//-----------------------------------------------------------------------------
void TextResource::unload(Allocator& allocator, void* resource)
{
	CE_ASSERT(resource != NULL, "Resource not loaded");

	((TextResource*)resource)->length = 0;

	allocator.deallocate(((TextResource*)resource)->data);
	allocator.deallocate(resource);
}
开发者ID:BasileusOnTop,项目名称:warzone-dcc,代码行数:10,代码来源:TextResource.cpp

示例13: Simple

  void Simple()
  {
    Allocator<DummyClass> allocator;

    DummyClass* p = allocator.allocate(1);
    allocator.construct(p, DummyClass());
    allocator.destroy(p);
    allocator.deallocate(p, 1);
  }
开发者ID:mutac,项目名称:Magnetometer,代码行数:9,代码来源:TestAllocator.cpp

示例14: CL_decodeDistributionPointName

/* This is always a DER-encoded blob at the NSS level */
void CL_decodeDistributionPointName(
	const CSSM_DATA				&nssBlob,
	CE_DistributionPointName	&cssmDpn,
	SecNssCoder					&coder,
	Allocator				&alloc)
{
	memset(&cssmDpn, 0, sizeof(CE_DistributionPointName));
	if(nssBlob.Length == 0) {
		clErrorLog("***CL_decodeDistributionPointName: bad PointName\n");
		CssmError::throwMe(CSSMERR_CL_UNKNOWN_FORMAT);
	}
	unsigned char tag = nssBlob.Data[0] & SEC_ASN1_TAGNUM_MASK;
	switch(tag) {
		case NSS_DIST_POINT_FULL_NAME_TAG:
		{
			/* decode to temp coder memory */
			NSS_GeneralNames gnames;
			gnames.names = NULL;
			if(coder.decodeItem(nssBlob, kSecAsn1DistPointFullNameTemplate,
					&gnames)) {
				clErrorLog("***Error decoding DistPointFullName\n");
				CssmError::throwMe(CSSMERR_CL_UNKNOWN_FORMAT);
			}
			
			cssmDpn.nameType = CE_CDNT_FullName;
			cssmDpn.dpn.fullName = (CE_GeneralNames *)alloc.malloc(
				sizeof(CE_GeneralNames));
				
			/* copy out to caller */
			CL_nssGeneralNamesToCssm(gnames, 
				*cssmDpn.dpn.fullName, coder, alloc);
			break;
		}
		case NSS_DIST_POINT_RDN_TAG:
		{
			/* decode to temp coder memory */
			NSS_RDN rdn;
			memset(&rdn, 0, sizeof(rdn));
			if(coder.decodeItem(nssBlob, kSecAsn1DistPointRDNTemplate,
					&rdn)) {
				clErrorLog("***Error decoding DistPointRDN\n");
				CssmError::throwMe(CSSMERR_CL_UNKNOWN_FORMAT);
			}
			
			cssmDpn.nameType = CE_CDNT_NameRelativeToCrlIssuer;
			cssmDpn.dpn.rdn = (CSSM_X509_RDN_PTR)alloc.malloc(
				sizeof(CSSM_X509_RDN));
			
			/* copy out to caller */
			CL_nssRdnToCssm(rdn, *cssmDpn.dpn.rdn, alloc, coder);
			break;
		}
		default:
			clErrorLog("***Bad CE_DistributionPointName tag\n");
			CssmError::throwMe(CSSMERR_CL_UNKNOWN_FORMAT);
	}
}
开发者ID:Apple-FOSS-Mirror,项目名称:Security,代码行数:58,代码来源:clNssUtils.cpp

示例15: localPolicy

        /*!
         * \brief Copy cache content
         *
         * Assigns a copy of the elements in x as the new content for the cache. Usage counts for entries are copied too.
         * The elements contained in the object before the call are dropped, and replaced by copies of those in cache x, if any.
         * After a call to this member function, both the map object and x will have the same size and compare equal to each other.
         *
         * \param <x> a cache object with the same template parameters
         *
         * \return *this
         *
         * \see swap
         */
        cache<Key,Data,Policy,Compare,Allocator>& operator= ( const cache<Key,Data,Policy,Compare,Allocator>& x) {
            this->_storage=x._storage;
            this->_maxEntries=x._maxEntries;
            this->_currEntries=this->_storage.size();

            policy_type localPolicy(*x._policy);
            this->_policy = policyAlloc.allocate(1);
            policyAlloc.construct(this->_policy,localPolicy);
            return *this;
        }
开发者ID:akashihi,项目名称:stlcache,代码行数:23,代码来源:stlcache.hpp


注:本文中的Allocator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。