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; } }
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; }
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; }
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; }
/// 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; } }
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; }
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); } } }
int main( int argc, char* argv[] ) { srand( time( NULL ) ); Allocator a = Allocator( POOLSIZE, NCLIENTS ); a.start(); a.join(); }
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()); }
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); } }
/*! * \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); }
//----------------------------------------------------------------------------- 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); }
void Simple() { Allocator<DummyClass> allocator; DummyClass* p = allocator.allocate(1); allocator.construct(p, DummyClass()); allocator.destroy(p); allocator.deallocate(p, 1); }
/* 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); } }
void reset( int maxSize ) { l = 0; if ( maxSize && size > maxSize ) { al.Free(data); data = (char*)al.Malloc(maxSize); assert(data); size = maxSize; } }
/*! * \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; }
/// Reserve enough space for n elements void reserve( size_type n ) { if ( mCapacity < n ) { size_type oldCapacity = mCapacity; pointer oldData = mData; mCapacity = n; mData = mAlloc.allocate( mCapacity ); std::uninitialized_copy( oldData, oldData + mSize, mData ); mAlloc.deallocate( oldData, oldCapacity ); } }
void CL_freeAuthorityKeyId( CE_AuthorityKeyID &cdsaObj, Allocator &alloc) { alloc.free(cdsaObj.keyIdentifier.Data); CL_freeCssmGeneralNames(cdsaObj.generalNames, alloc); alloc.free(cdsaObj.generalNames); alloc.free(cdsaObj.serialNumber.Data); memset(&cdsaObj, 0, sizeof(CE_AuthorityKeyID)); }
AllocatorBlock allocate(size_t n) { if (n > max) { return {nullptr, 0}; } if ( (n - min) % step == 0) { return parent_.allocate(n); } else { auto delta = (n - min)/step + 1; return parent_.allocate(min + delta * step); } }
void first_allocated_last_deallocated_batch() { uint32* p[N]; for (size_t i = 0; i < N; ++i) p[i] = m_allocator.allocate(1); for (size_t i = N; i; --i) m_allocator.deallocate(p[i - 1], 1); }
inline bool Spec::get_first_column_type_from_ref(ref_type top_ref, Allocator& alloc, ColumnType& type) noexcept { const char* top_header = alloc.translate(top_ref); ref_type types_ref = to_ref(Array::get(top_header, 0)); const char* types_header = alloc.translate(types_ref); if (Array::get_size_from_header(types_header) == 0) return false; type = ColumnType(Array::get(types_header, 0)); return true; }
static std::chrono::nanoseconds benchmark(const Allocator &allocator) { using namespace std::chrono; const auto start = steady_clock::now(); size_t count = 0; for (; steady_clock::now() - start < benchduration; ++count) { const auto pData = allocator.malloc(imageSize); allocator.free(pData); } return duration_cast<nanoseconds>(benchduration) / count; }
void CL_freeCssmAlgId( CSSM_X509_ALGORITHM_IDENTIFIER *cdsaObj, // optional Allocator &alloc) { if(cdsaObj == NULL) { return; } alloc.free(cdsaObj->algorithm.Data); alloc.free(cdsaObj->parameters.Data); memset(cdsaObj, 0, sizeof(CSSM_X509_ALGORITHM_IDENTIFIER)); }
void CL_freeOtherName( CE_OtherName *cssmOther, Allocator &alloc) { if(cssmOther == NULL) { return; } alloc.free(cssmOther->typeId.Data); alloc.free(cssmOther->value.Data); memset(cssmOther, 0, sizeof(*cssmOther)); }
void CL_freeInfoAccess( CE_AuthorityInfoAccess &cssmInfo, Allocator &alloc) { uint32 numDescs = cssmInfo.numAccessDescriptions; for(unsigned dex=0; dex<numDescs; dex++) { CE_AccessDescription *dst = &cssmInfo.accessDescriptions[dex]; alloc.free(dst->accessMethod.Data); CL_freeCssmGeneralName(dst->accessLocation, alloc); } alloc.free(cssmInfo.accessDescriptions); }
void free(view_type& rng) { Allocator allocator; if(rng.data()) allocator.deallocate(rng.data(), rng.size()); #ifdef VERBOSE std::cerr << util::type_printer<DeviceCoordinator>::print() << "::free()" << std::endl; #endif impl::reset(rng); }
void js::Nursery::moveElementsToTenured(JSObject *dst, JSObject *src, AllocKind dstKind) { if (src->hasEmptyElements()) return; Allocator *alloc = &src->zone()->allocator; ObjectElements *srcHeader = src->getElementsHeader(); ObjectElements *dstHeader; if (!isInside(srcHeader)) { JS_ASSERT(src->elements == dst->elements); hugeSlots.remove(reinterpret_cast<HeapSlot*>(srcHeader)); return; } /* ArrayBuffer stores byte-length, not Value count. */ if (src->isArrayBuffer()) { size_t nbytes = sizeof(ObjectElements) + srcHeader->initializedLength; if (src->hasDynamicElements()) { dstHeader = static_cast<ObjectElements *>(alloc->malloc_(nbytes)); if (!dstHeader) MOZ_CRASH(); } else { dst->setFixedElements(); dstHeader = dst->getElementsHeader(); } js_memcpy(dstHeader, srcHeader, nbytes); dst->elements = dstHeader->elements(); return; } size_t nslots = ObjectElements::VALUES_PER_HEADER + srcHeader->initializedLength; /* Unlike other objects, Arrays can have fixed elements. */ if (src->isArray() && nslots <= GetGCKindSlots(dstKind)) { dst->setFixedElements(); dstHeader = dst->getElementsHeader(); js_memcpy(dstHeader, srcHeader, nslots * sizeof(HeapSlot)); dstHeader->capacity = GetGCKindSlots(dstKind) - ObjectElements::VALUES_PER_HEADER; return; } size_t nbytes = nslots * sizeof(HeapValue); dstHeader = static_cast<ObjectElements *>(alloc->malloc_(nbytes)); if (!dstHeader) MOZ_CRASH(); js_memcpy(dstHeader, srcHeader, nslots * sizeof(HeapSlot)); dstHeader->capacity = srcHeader->initializedLength; dst->elements = dstHeader->elements(); }
void CssmDbAttributeData::deleteValues(Allocator &alloc) { // Loop over all values and delete each one. if (values()) { for (uint32 n = 0; n < size(); n++) { alloc.free(at(n).data()); } alloc.free(values()); } NumberOfValues = 0; values() = NULL; }
view_type allocate(size_type n) { Allocator allocator; pointer ptr = n>0 ? allocator.allocate(n) : nullptr; #ifdef VERBOSE std::cerr << util::type_printer<DeviceCoordinator>::print() << util::blue("::allocate") << "(" << n << ")" << (ptr==nullptr && n>0 ? " failure" : " success") << std::endl; #endif return view_type(ptr, n); }
/// Allocates a memory block of the requested size. The blocks are created from /// the fixed block allocators. /// @param[in] size - the client requested size of the block. /// @return A pointer to the client's memory block. extern "C" void *xmalloc(size_t size) { lock_get(); // Allocate a raw memory block Allocator* allocator = xallocator_get_allocator(size); void* blockMemoryPtr = allocator->Allocate(size); lock_release(); // Set the block Allocator* within the raw memory block region void* clientsMemoryPtr = set_block_allocator(blockMemoryPtr, allocator); return clientsMemoryPtr; }