本文整理汇总了C++中Alloc类的典型用法代码示例。如果您正苦于以下问题:C++ Alloc类的具体用法?C++ Alloc怎么用?C++ Alloc使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Alloc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tlist
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);
}
示例2:
~Array1D() {
Alloc alloc;
for (int i = 0; i < mSize; ++i) {
alloc.destroy(&mData[i]);
}
alloc.deallocate(mData, mSize);
}
示例3: destroy
void destroy() {
if (m_t) {
Alloc a;
m_t->~T();
a.deallocate(m_t, 1);
}
}
示例4: WeightedDirectedGraphAsAdjMatrix
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;
}
}
示例5: Array1D
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);
}
}
}
示例6: uninitialized_fill_n_with_alloc
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
}
示例7: new
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);
}
示例8: uninitialized_copy_with_alloc
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;
}
示例9: allocator
// 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);
}
示例10: call_select_on_container_copy_construction
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();
}
示例11:
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);
}
示例12: tlist1
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);
}
示例13: get_context
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;
}
示例14: shafile
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());
}
示例15: construct_each_impl2
__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()