void TC_MemFail03::run() { MemoryControlWithFailure mc; mc.resetCounters(); mc.disableLimit(); Alloc<REToken *> alloc; alloc.setMC(&mc); { TokenList tlist(&mc, alloc, "[a-z]"); } size_t numAllocs = mc.m_numAllocs; for (size_t lim = 0; lim < numAllocs; lim++) { mc.resetCounters(); mc.setLimit(lim); try { TokenList tlist(&mc, alloc, "[a-z]"); ASSERT_TRUE(false); } catch (const bad_alloc &e) { ASSERT_TRUE(true); } } this->setStatus(true); }
~Array1D() { Alloc alloc; for (int i = 0; i < mSize; ++i) { alloc.destroy(&mData[i]); } alloc.deallocate(mData, mSize); }
void TC_Postfix05::run() { MemoryControl mc; Alloc<REToken *> alloc; alloc.setMC(&mc); TokenList2 tlist(&mc, alloc); tlist.build("a(b|c)d"); TokenList2 tlist2(&mc, alloc); TokenList2::tmpTokList tmpList; tlist2.buildPostfix(&tlist, &tmpList); tlist2.beginIteration(); ASSERT_TRUE(tlist2.verifyNext(TT_SELF_CHAR, 'a')); ASSERT_TRUE(tlist2.verifyNext(TT_SELF_CHAR, 'b')); ASSERT_TRUE(tlist2.verifyNext(TT_SELF_CHAR, 'c')); ASSERT_TRUE(tlist2.verifyNext(TT_PIPE)); ASSERT_TRUE(tlist2.verifyNext(TT_CCAT)); ASSERT_TRUE(tlist2.verifyNext(TT_SELF_CHAR, 'd')); ASSERT_TRUE(tlist2.verifyNext(TT_CCAT)); ASSERT_TRUE(tlist2.verifyEnd()); this->setStatus(true); }
void TC_Tokens05::run() { MemoryControl mc; Alloc<REToken *> alloc; alloc.setMC(&mc); { TokenList tlist(&mc, alloc, "[^abc]"); tlist.beginIteration(); ASSERT_TRUE(tlist.verifyCharClassLength(256 - 3)); tlist.incrementIterator(); ASSERT_TRUE(tlist.verifyEnd()); } { TokenList tlist(&mc, alloc, "[^abc]"); tlist.beginIteration(); ASSERT_TRUE(tlist.verifyCharClassMember('z')); ASSERT_TRUE( ! tlist.verifyCharClassMember('a')); tlist.incrementIterator(); ASSERT_TRUE(tlist.verifyEnd()); } this->setStatus(true); }
void destroy() { if (m_t) { Alloc a; m_t->~T(); a.deallocate(m_t, 1); } }
WeightedDirectedGraphAsAdjMatrix(int numVertex, T initWeight = T()) : mNumVertex(numVertex) { int size = mNumVertex * mNumVertex; Alloc alloc; mData = alloc.allocate(size); for (int i = 0; i < size; ++i) { mData[i] = initWeight; } }
Array1D(int size, bool init = false, T initValue = T()) : mSize(size) { Alloc alloc; mData = alloc.allocate(mSize); if (init) { for (int i = 0; i < mSize; ++i) { alloc.construct(&mData[i], initValue); } } }
void TC_Tokens207::run() { MemoryControl mc; Alloc<REToken *> alloc; alloc.setMC(&mc); try { TokenList2 tlist(&mc, alloc); tlist.build("{2 2}"); ASSERT_TRUE(false); } catch (const SyntaxError &e) { ASSERT_TRUE(e.getErrorIndex() == 3); } try { TokenList2 tlist(&mc, alloc); tlist.build("{2 2}"); ASSERT_TRUE(false); } catch (const SyntaxError &e) { ASSERT_TRUE(e.getErrorIndex() == 4); } try { TokenList2 tlist(&mc, alloc); tlist.build("{2-}"); ASSERT_TRUE(false); } catch (const SyntaxError &e) { ASSERT_TRUE(e.getErrorIndex() == 2); } try { TokenList2 tlist(&mc, alloc); tlist.build("{9999999999999999999999999999999999999999999}"); ASSERT_TRUE(false); } catch (const SyntaxError &e) { ASSERT_TRUE(true); } try { TokenList2 tlist(&mc, alloc); tlist.build("{9, 99999999999999999999999999999999999999999999}"); ASSERT_TRUE(false); } catch (const SyntaxError &e) { ASSERT_TRUE(true); } this->setStatus(true); }
inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const T& item, Alloc& alloc) { ForwardIterator next = first; BOOST_TRY { for (; n > 0; ++first, --n) alloc.construct(first, item); } BOOST_CATCH(...) { for (; next != first; ++next) alloc.destroy(next); BOOST_RETHROW } BOOST_CATCH_END }
void TC_Tokens02::run() { MemoryControl mc; Alloc<REToken *> alloc; alloc.setMC(&mc); TokenList tlist(&mc, alloc, "a"); TokenList::TokList::iterator iter = tlist.m_toks.begin(); ASSERT_TRUE(tlist.equals(iter, TT_SELF_CHAR, 'a')); this->setStatus(true); }
void TC_Basic02::run() { MemoryControl mc; Alloc<REToken *> alloc; alloc.setMC(&mc); TokenList *toks = new (&mc) TokenList(&mc, alloc, ""); toks->~TokenList(); mc.deallocate(toks, 1); this->setStatus(true); }
inline ForwardIterator uninitialized_copy_with_alloc(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& alloc) { ForwardIterator next = dest; BOOST_TRY { for (; first != last; ++first, ++dest) alloc.construct(dest, *first); } BOOST_CATCH(...) { for (; next != dest; ++next) alloc.destroy(next); BOOST_RETHROW } BOOST_CATCH_END return dest; }
// variableLengthOffsetStart // ^ _____________ // | | | // |______________________||____________||______V___________________| // int,date(long),float offsets strings/variable length // |____________________________________| // Fixed Length | // V // fixedSizedOffset // // offsets() creates a pair of arrays with offset at each index to its // associated Attribute's offset in the returned serialized buffer // It uses maxOffsetBuffer and lastOffsetOfWrittenBuffer as temporary // holders to fill in the const members: fixedSizedOffset, // variableLengthOffsetStart // RecordSerializer::RecordSerializer(srch2::instantsearch::Schema& schema, Alloc& allocator) : allocator(allocator), schema(schema), maxOffsetOfBuffer(0), lastOffsetOfWrittenBuffer(0), offsets(initAttributeOffsetArray(schema, maxOffsetOfBuffer, lastOffsetOfWrittenBuffer)), fixedSizedOffset(maxOffsetOfBuffer), variableLengthOffsetStart(lastOffsetOfWrittenBuffer) { lastOffsetOfWrittenBuffer = fixedSizedOffset; //rounds default size of the nearest allocation page size maxOffsetOfBuffer = allocator.round(fixedSizedOffset + DEFAULT_VARIBLE_ATTRIBUTE_LENGTH * (offsets.first.size())); buffer = allocator.allocate(maxOffsetOfBuffer); std::memset(buffer, 0x0, fixedSizedOffset); }
inline typename boost::enable_if_c< boost::unordered::detail:: has_select_on_container_copy_construction<Alloc>::value, Alloc >::type call_select_on_container_copy_construction(const Alloc& rhs) { return rhs.select_on_container_copy_construction(); }
void TC_MemFail2_04::run() { MemoryControlWithFailure mc; mc.resetCounters(); mc.disableLimit(); Alloc<REToken *> alloc; alloc.setMC(&mc); this->checkOneRegex(mc, alloc, "abc"); this->checkOneRegex(mc, alloc, "a{2,10}"); this->checkOneRegex(mc, alloc, "a"); this->checkOneRegex(mc, alloc, "a{2}"); this->setStatus(true); }
void TC_MemFail2_05::run() { MemoryControlWithFailure mc; mc.resetCounters(); mc.disableLimit(); Alloc<REToken *> alloc; alloc.setMC(&mc); this->expectFailure(mc, alloc, "{2 2}"); this->expectFailure(mc, alloc, "{2 - }"); this->expectFailure(mc, alloc, "{999999999999999999999999999999999"); this->expectFailure(mc, alloc, "a{2,99999999999999999999999999999999999}"); this->setStatus(true); }
PUBLIC void Kmem_alloc::unaligned_free(unsigned long size, void *page) { assert(size >=8 /*NEW INTERFACE PARANIOIA*/); auto guard = lock_guard(lock); a->free(page, size); }
void TC_MemFail01::run() { MemoryControl mc; Alloc<REToken *> alloc; alloc.setMC(&mc); try { TokenList tlist(&mc, alloc, "a[b"); ASSERT_TRUE(false); } catch (const SyntaxError &e) { ASSERT_TRUE(e.getErrorIndex() == 1); } this->setStatus(true); }
void TC_Tokens209::run() { MemoryControl mc; Alloc<REToken *> alloc; alloc.setMC(&mc); for (char c1 = ' '; c1 <= '~'; c1++) { TokenList2 tlist(&mc, alloc); char buf[3]; switch (c1) { case '(': case ')': case '[': case ']': case '{': case '}': case '\\': case '*': case '?': case '+': case '|': buf[0] = '\\'; buf[1] = c1; buf[2] = '\0'; break; default: buf[0] = c1; buf[1] = '\0'; buf[2] = '\0'; break; } tlist.build(buf); tlist.beginIteration(); ASSERT_TRUE(tlist.verifyNext(TT_SELF_CHAR, c1)); ASSERT_TRUE(tlist.verifyEnd()); } this->setStatus(true); }
void TC_Postfix_MemFail_01::run() { MemoryControlWithFailure mc; mc.resetCounters(); mc.disableLimit(); Alloc<REToken *> alloc; alloc.setMC(&mc); { TokenList2 tlist1(&mc, alloc); TokenList2 tlist2(&mc, alloc); TokenList2::tmpTokList tmpList; tlist1.build("a"); tlist2.buildPostfix(&tlist1, &tmpList); } size_t numAllocs = mc.m_numAllocs; for (size_t lim = 0; lim < numAllocs; lim++) { mc.resetCounters(); mc.setLimit(lim); try { TokenList2 tlist1(&mc, alloc); tlist1.build("a"); TokenList2 tlist2(&mc, alloc); TokenList2::tmpTokList tmpList; tlist2.buildPostfix(&tlist1, &tmpList); ASSERT_TRUE(false); } catch (const bad_alloc &e) { ASSERT_TRUE(true); } } this->setStatus(true); }
PUBLIC void * Kmem_alloc::unaligned_alloc(unsigned long size) { assert(size >=8 /*NEW INTERFACE PARANIOIA*/); void* ret; { auto guard = lock_guard(lock); ret = a->alloc(size); } if (!ret) { Kmem_alloc_reaper::morecore (/* desperate= */ true); auto guard = lock_guard(lock); ret = a->alloc(size); } return ret; }
ResizeContext Resize::get_context(Alloc &alloc, PixelType type) const { ResizeContext ctx{}; if (!m_skip_h && !m_skip_v) { double xscale = (double)m_dst_width / (double)m_src_width; double yscale = (double)m_dst_height / (double)m_src_height; bool h_first = resize_h_first(xscale, yscale); ctx.impl1 = h_first ? m_impl_h.get() : m_impl_v.get(); ctx.impl2 = h_first ? m_impl_v.get() : m_impl_h.get(); ctx.tmp_width = h_first ? m_dst_width : m_src_width; ctx.tmp_height = h_first ? m_src_height : m_dst_height; ctx.in_buffering1 = std::min(ctx.impl1->input_buffering(type), m_src_height); ctx.in_buffering2 = std::min(ctx.impl2->input_buffering(type), ctx.tmp_height); ctx.out_buffering1 = ctx.impl1->output_buffering(type); ctx.out_buffering2 = ctx.impl2->output_buffering(type); ctx.src_border_buf = alloc_line_buffer(alloc, ctx.in_buffering1, m_src_width, type); ctx.dst_border_buf = alloc_line_buffer(alloc, ctx.out_buffering2, m_dst_width, type); ctx.tmp_buf = alloc_line_buffer(alloc, ctx.out_buffering1 + ctx.in_buffering2 - 1, ctx.tmp_width, type); ctx.tmp_data = alloc.allocate(std::max(ctx.impl1->tmp_size(type, ctx.tmp_width), ctx.impl2->tmp_size(type, m_dst_width))); } else if (!(m_skip_h && m_skip_v)) { ctx.impl1 = m_impl_h ? m_impl_h.get() : m_impl_v.get(); ctx.in_buffering1 = std::min(ctx.impl1->input_buffering(type), m_src_height); ctx.out_buffering1 = ctx.impl1->output_buffering(type); ctx.src_border_buf = alloc_line_buffer(alloc, ctx.in_buffering1, m_src_width, type); ctx.dst_border_buf = alloc_line_buffer(alloc, ctx.out_buffering1, m_dst_width, type); ctx.tmp_data = alloc.allocate(ctx.impl1->tmp_size(type, m_dst_width)); } return ctx; }
void shafile(const string &baseDir, const string &file) { unsigned char digest[SHA256_DIGEST_LENGTH]; SHA256_CTX c; string fullFile(prependBaseDir(baseDir, file)); FastOS_File f; std::ostringstream os; Alloc buf = Alloc::alloc(65536, MemoryAllocator::HUGEPAGE_SIZE, 0x1000); f.EnableDirectIO(); bool openres = f.OpenReadOnly(fullFile.c_str()); if (!openres) { LOG(error, "Could not open %s for sha256 checksum", fullFile.c_str()); LOG_ABORT("should not be reached"); } int64_t flen = f.GetSize(); int64_t remainder = flen; SHA256_Init(&c); while (remainder > 0) { int64_t thistime = std::min(remainder, static_cast<int64_t>(buf.size())); f.ReadBuf(buf.get(), thistime); SHA256_Update(&c, buf.get(), thistime); remainder -= thistime; } f.Close(); SHA256_Final(digest, &c); for (unsigned int i = 0; i < SHA256_DIGEST_LENGTH; ++i) { os.width(2); os.fill('0'); os << std::hex << static_cast<unsigned int>(digest[i]); } LOG(info, "SHA256(%s)= %s", file.c_str(), os.str().c_str()); }
__AGENCY_ANNOTATION typename std::enable_if< has_construct<Alloc,typename std::iterator_traits<Iterator>::pointer, Args...>::value, Iterator >::type construct_each_impl2(Alloc& a, Iterator first, Iterator last, Args&&... args) { for(; first != last; ++first) { a.construct(&*first, std::forward<Args>(args)...); } return first; } // end construct_each_impl2()
void setup() { synth = new SYNTH_T; synth->buffersize = 256; synth->samplerate = 48000; synth->alias(); time_ = new AbsTime(*synth); //for those patches that are just really big alloc.addMemory(malloc(1024*1024),1024*1024); outL = new float[1024]; for(int i = 0; i < synth->buffersize; ++i) outL[i] = 0.0f; outR = new float[1024]; for(int i = 0; i < synth->buffersize; ++i) outR[i] = 0.0f; p = new Part(alloc, *synth, *time_, compress, interp, µtonal, &fft); }
static void deallocate(Alloc& a, pointer p, size_type n) { a.deallocate(p, n); }
static pointer allocate(Alloc& a, size_type n) { return a.allocate(n); }
inline typename boost::enable_if_c< boost::unordered::detail::has_max_size<Alloc>::value, SizeType >::type call_max_size(const Alloc& a) { return a.max_size(); }
initer() : a() , success(false) , m_t(nullptr) { m_t = a.allocate(1); }
~initer() { if (!success) { a.deallocate(m_t, 1); } }