• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ allocator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: encode_omdl

blob encode_omdl(const model& mdl
	, const allocator& file_alloc
	, const allocator& temp_alloc)
{
	const auto& info = mdl.info();

	uint32_t nslots = info.num_slots;
	const auto subsets_bytes = info.num_subsets * (uint32_t)sizeof(subset_t);
	const auto indices_bytes = info.num_indices * (uint32_t)sizeof(uint16_t);
	const auto vertices_bytes = info.num_vertices * layout_size(info.layout);

	const auto bytes = sizeof(file_header) 
		+ sizeof(file_chunk) + sizeof(info_t) 
		+ sizeof(file_chunk) + subsets_bytes
		+ sizeof(file_chunk) + indices_bytes
		+ sizeof(file_chunk) * nslots + vertices_bytes;

	auto mem = file_alloc.scoped_allocate(bytes, "encoded model");
	auto hdr = (file_header*)mem;

	hdr->fourcc = omdl_signature;
	hdr->num_chunks = 4;
	hdr->compression = compression_type::none; // not yet implemented, though here's where it gets done
	hdr->reserved = 0;
	hdr->version_hash = 0; // not yet implemented

	auto chk = hdr->first_chunk();
	chk->fourcc = omdl_info_signature;
	chk->chunk_bytes = sizeof(info_t);
	chk->uncompressed_bytes = chk->chunk_bytes;
	memcpy(chk->data<info_t>(), &info, sizeof(info_t));

	chk = chk->next();
	chk->fourcc = omdl_subsets_signature;
	chk->chunk_bytes = subsets_bytes;
	chk->uncompressed_bytes = chk->chunk_bytes;
	memcpy(chk->data<subset_t>(), mdl.subsets(), chk->chunk_bytes);

	chk = chk->next();
	chk->fourcc = omdl_indices_signature;
	chk->chunk_bytes = indices_bytes;
	chk->uncompressed_bytes = chk->chunk_bytes;
	memcpy(chk->data<uint16_t>(), mdl.indices(), chk->chunk_bytes);

	for (uint32_t slot = 0; slot < nslots; slot++)
	{
		chk = chk->next();
		chk->fourcc = omdl_vertex_slot_signature;
		chk->chunk_bytes = vertices_bytes;
		chk->uncompressed_bytes = chk->chunk_bytes;
		memcpy(chk->data<void>(), mdl.vertices(slot), chk->chunk_bytes);
	}

	return mem;
}
开发者ID:igHunterKiller,项目名称:ouroboros,代码行数:55,代码来源:omdl.cpp


示例2: get_double_float_array

core::result details::get_double_float_array(
    const char * * buffers, const std::size_t * sizes,
    std::size_t num_of_buffers,
    std::size_t & current_buffer, const char * & buffer_position,
    double * & values, std::size_t & length,
    allocator & alloc)
{
    int raw_length;
    core::result res = get_integer(buffers, sizes, num_of_buffers,
        current_buffer, buffer_position, raw_length);

    if (res == core::ok)
    {
        length = static_cast<std::size_t>(raw_length);

        double * new_array = static_cast<double *>(
            alloc.allocate(length * sizeof(double)));
        if (new_array != NULL)
        {
            values = new_array;

            for (std::size_t i = 0; res == core::ok && i != length; ++i)
            {
                res = get_double_float(buffers, sizes, num_of_buffers,
                    current_buffer, buffer_position, values[i]);
            }

            if (res != core::ok)
            {
                alloc.deallocate(new_array);
            }
        }
        else
        {
            res = core::no_memory;
        }
    }

    return res;
}
开发者ID:morambro,项目名称:TrainProject,代码行数:40,代码来源:serialization.cpp


示例3: get_string

core::result details::get_string(const char * * buffers,
    const std::size_t * sizes,
    std::size_t num_of_buffers,
    std::size_t & current_buffer, const char * & buffer_position,
    const char * & value, std::size_t & length,
    allocator & alloc)
{
    int raw_length;
    core::result res = get_integer(buffers, sizes, num_of_buffers,
        current_buffer, buffer_position, raw_length);

    if (res == core::ok)
    {
        length = static_cast<std::size_t>(raw_length);

        char * new_buffer =
            static_cast<char *>(alloc.allocate(length));
        if (new_buffer != NULL)
        {
            value = new_buffer;

            res = get_raw_string(buffers, sizes, num_of_buffers,
                current_buffer, buffer_position,
                new_buffer, length);

            if (res != core::ok)
            {
                alloc.deallocate(new_buffer);
            }
        }
        else
        {
            res = core::no_memory;
        }
    }

    return res;
}
开发者ID:morambro,项目名称:TrainProject,代码行数:38,代码来源:serialization.cpp


示例4: get_boolean_array

core::result details::get_boolean_array(
    const char * * buffers, const std::size_t * sizes,
    std::size_t num_of_buffers,
    std::size_t & current_buffer, const char * & buffer_position,
    bool * & values, std::size_t & length,
    allocator & alloc)
{
    int raw_length;
    core::result res = get_integer(buffers, sizes, num_of_buffers,
        current_buffer, buffer_position, raw_length);

    if (res == core::ok)
    {
        length = static_cast<std::size_t>(raw_length);

        const std::size_t byte_length = length * sizeof(bool);
        bool * new_array = static_cast<bool *>(
            alloc.allocate(byte_length));
        if (new_array != NULL)
        {
            std::memset(new_array, 0, byte_length);

            values = new_array;

            const std::size_t full_words = length / bits_in_word;
            char word[bytes_in_word];

            // first process full words
            for (std::size_t i = 0; i != full_words; ++i)
            {
                res = get_word_preserve_order(
                    buffers, sizes, num_of_buffers,
                    current_buffer, buffer_position, word);
                if (res != core::ok)
                {
                    break;
                }

                for (std::size_t j = 0; j != bits_in_word; ++j)
                {
                    const std::size_t byte_position = j / bits_in_byte;
                    const std::size_t bit_position = j % bits_in_byte;

                    if (word[byte_position] & (1 << bit_position))
                    {
                        values[i * bits_in_word + j] = true;
                    }
                }
            }

            // tail (what could not be read as a full word)
            if (res == core::ok)
            {
                res = get_word_preserve_order(
                    buffers, sizes, num_of_buffers,
                    current_buffer, buffer_position, word);

                if (res == core::ok)
                {
                    const std::size_t already_read_bits =
                        full_words * bits_in_word;

                    for (std::size_t j = already_read_bits;
                         j != length; ++j)
                    {
                        const std::size_t byte_position =
                            (j - already_read_bits) / bits_in_byte;
                        const std::size_t bit_position = j % bits_in_byte;

                        if (word[byte_position] & (1 << bit_position))
                        {
                            values[j] = true;
                        }
                    }
                }
            }

            if (res != core::ok)
            {
                alloc.deallocate(new_array);
            }
        }
        else
        {
            res = core::no_memory;
        }
    }

    return res;
}
开发者ID:morambro,项目名称:TrainProject,代码行数:90,代码来源:serialization.cpp


示例5: undo_state

 undo_state( allocator<T> al )
 :old_values( id_value_allocator_type( al.get_segment_manager() ) ),
  removed_values( id_value_allocator_type( al.get_segment_manager() ) ),
  new_ids( id_allocator_type( al.get_segment_manager() ) ){}
开发者ID:mingyukim123,项目名称:steem,代码行数:4,代码来源:chainbase.hpp


示例6: free

void String::free()
{
    if (elements) {
        std::for_each(elements, end, [this](char &c){ alloc.destroy(&c); });
        alloc.deallocate(elements, end - elements);
    }   
}
开发者ID:magastzheng,项目名称:CppPrimer,代码行数:7,代码来源:ex13_44.cpp


示例7: free

void StrVec::free() {
	if (elements) {
		for (auto p = first_free; p != elements;) {
			alloc.destroy(--p);
		}
		alloc.deallocate(elements, cap - elements);
	}
}
开发者ID:PayneSun,项目名称:FirstRepository,代码行数:8,代码来源:source.cpp


示例8: release

inline void BigNumber::release()
{//Free BigNumber space
    if(first_free){
        while(first_free != val) alloc.destroy(--first_free);
        alloc.deallocate(val,cap);
    }
    val=first_free=NULL;
    cap=len=dot=0;
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:9,代码来源:BigNumber+Class.cpp


示例9:

inline BigNumber::~BigNumber()
{//Destructor
    if(val){
        for(;first_free!=val;)
            alloc.destroy(--first_free);
        alloc.deallocate(val,cap);
    }
    val=first_free=NULL;
    cap=0;
    dot=len=0;
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:11,代码来源:BigNumber+Class.cpp


示例10: free

String &String::operator=(const String &str)
{
    char *p = alloc.allocate(str.sz);
    char *q = p;
    for(size_t i = 0;i < str.sz; ++i)
        alloc.construct(q++,str.s[i]);
    free();
    s = p;
    sz = str.sz;
    return *this;

}
开发者ID:Edward-surpass,项目名称:Cplusplusprimer5,代码行数:12,代码来源:14.26ff.cpp


示例11: while

BigNumber& BigNumber::reverse_copy(BigNumber &A)
{//Reverse copy
    cap=len=A.len;
    val=alloc.allocate(cap);
    first_free=val;
    dot=0;
    unsigned char *begin=A.first_free;
    while(begin!=A.val){
        alloc.construct(first_free++,*--begin);
        if(*begin=='.') dot=first_free-val-1;
    }
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:12,代码来源:BigNumber+Class.cpp


示例12: reallocate

void StrVec::reallocate() {
	auto newcapacity = size() ? 2 * size() : 1;
	auto newdata = alloc.allocate(newcapacity);
	auto dest = newdata;
	auto elem = elements;
	0
	for (size_t i = 0; i != size(); ++i) {
		alloc.construct(dest++, std::move(*elem++));
	}
	free();
	elements = newdata;
	first_free = dest;
	cap = elements + newcapacity;
}
开发者ID:PayneSun,项目名称:FirstRepository,代码行数:14,代码来源:source.cpp


示例13: push_back

void BigNumber::push_back(const unsigned char c)
{//Push a character back
    if(!len||len>=cap){
        int newcap=cap?(2*cap):2;
        int newdot=dot;
        unsigned char *newval=alloc.allocate(newcap);
        unsigned char *newfirst_free=newval;
        unsigned char *oldval=val;
        while(oldval!=first_free) alloc.construct(newfirst_free++,*oldval++);
        alloc.construct(newfirst_free++,c);
        release();
        val=newval;
        first_free=newfirst_free;
        len=first_free-val;
        cap=newcap;
        dot=newdot;
    }else{alloc.construct(first_free++,c);len++;}
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:18,代码来源:BigNumber+Class.cpp


示例14: cut_tail

void BigNumber::cut_tail(int num)
{
    int newcap = num + 3;
    int newdot;
    unsigned char *newval = alloc.allocate(newcap);
    unsigned char *newfirst_free = newval;
    unsigned char *oldval = val;
    while((first_free - oldval) != newcap) ++oldval;
    unsigned char *start = oldval;
    while(oldval != first_free){
        if(*oldval == '.') newdot = oldval - start;
        alloc.construct(newfirst_free++,*oldval++);
    }
    release();
    val=newval;
    first_free=newfirst_free;
    len=first_free-val;
    cap=newcap;
    dot=newdot;
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:20,代码来源:BigNumber+Class.cpp


示例15: push_front

void BigNumber::push_front(int num,const unsigned char c)
{//Push multiple characters front
    if(!len){
        cap=len=num+1;
        val=alloc.allocate(cap);
        first_free=val;
        dot=0;
        while(num--) alloc.construct(first_free++,c);
        alloc.construct(first_free++,'+');
    }else{
        int newcap=len+num;
        int newdot=dot;
        unsigned char *newval=alloc.allocate(newcap);
        unsigned char *newfirst_free=newval;
        unsigned char *oldval=val;
        while(num--) alloc.construct(newfirst_free++,c);
        while(oldval!=first_free)
            alloc.construct(newfirst_free++,*oldval++);
        release();
        val=newval;
        first_free=newfirst_free;
        cap=len=newcap;
        dot=newdot;
    }
}
开发者ID:hdzz,项目名称:BigNumber,代码行数:25,代码来源:BigNumber+Class.cpp


示例16: create

 static T* create() {
     T* p = alloc_.allocate(1);
     if (!p) return nullptr;
     alloc_.construct(p);
     return p;
 };
开发者ID:Stone1973,项目名称:crossbow,代码行数:6,代码来源:singleton.hpp


示例17: destroy

 static void destroy(T* ptr) {
     alloc_.destroy(ptr);
     alloc_.deallocate(ptr, 1);
 }
开发者ID:Stone1973,项目名称:crossbow,代码行数:4,代码来源:singleton.hpp


示例18: push_back

void StrVec::push_back(const string& s) {
	chk_n_alloc();
	alloc.construct(first_free++, s);
}
开发者ID:PayneSun,项目名称:FirstRepository,代码行数:4,代码来源:source.cpp


示例19:

pair<string*, string*> StrVec::alloc_n_copy(const string *b, const string *e) {
	auto data = alloc.allocate(e - b);

	return { data, uninitialized_copy(b, e, data) };
}
开发者ID:PayneSun,项目名称:FirstRepository,代码行数:5,代码来源:source.cpp


示例20:

pair<char*, char*> String::alloc_n_copy(const char* b, const char* e)
{
    auto str = alloc.allocate(e - b);
    return {str, uninitialized_copy(b, e, str)};
}
开发者ID:magastzheng,项目名称:CppPrimer,代码行数:5,代码来源:ex13_44.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ allocator_type类代码示例发布时间:2022-05-31
下一篇:
C++ alignment类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap