x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
quick_allocator.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\detail\quick_allocator.hpp
旋转
特效
属性
历史版本
#ifndef BOOST_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED #define BOOST_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED // MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif // // detail/quick_allocator.hpp // // Copyright (c) 2003 David Abrahams // Copyright (c) 2003 Peter Dimov // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #include
#include
#include
#include
#include
// ::operator new, ::operator delete #include
// std::size_t namespace boost { namespace detail { template
union freeblock { typedef typename boost::type_with_alignment
::type aligner_type; aligner_type aligner; char bytes[size]; freeblock * next; }; template
struct allocator_impl { typedef freeblock
block; // It may seem odd to use such small pages. // // However, on a typical Windows implementation that uses // the OS allocator, "normal size" pages interact with the // "ordinary" operator new, slowing it down dramatically. // // 512 byte pages are handled by the small object allocator, // and don't interfere with ::new. // // The other alternative is to use much bigger pages (1M.) // // It is surprisingly easy to hit pathological behavior by // varying the page size. g++ 2.96 on Red Hat Linux 7.2, // for example, passionately dislikes 496. 512 seems OK. #if defined(BOOST_QA_PAGE_SIZE) enum { items_per_page = BOOST_QA_PAGE_SIZE / size }; #else enum { items_per_page = 512 / size }; // 1048560 / size #endif #ifdef BOOST_HAS_THREADS static lightweight_mutex & mutex() { static lightweight_mutex m; return m; } static lightweight_mutex * mutex_init; #endif static block * free; static block * page; static unsigned last; static inline void * alloc() { #ifdef BOOST_HAS_THREADS lightweight_mutex::scoped_lock lock( mutex() ); #endif if(block * x = free) { free = x->next; return x; } else { if(last == items_per_page) { // "Listen to me carefully: there is no memory leak" // -- Scott Meyers, Eff C++ 2nd Ed Item 10 page = ::new block[items_per_page]; last = 0; } return &page[last++]; } } static inline void * alloc(std::size_t n) { if(n != size) // class-specific new called for a derived object { return ::operator new(n); } else { #ifdef BOOST_HAS_THREADS lightweight_mutex::scoped_lock lock( mutex() ); #endif if(block * x = free) { free = x->next; return x; } else { if(last == items_per_page) { page = ::new block[items_per_page]; last = 0; } return &page[last++]; } } } static inline void dealloc(void * pv) { if(pv != 0) // 18.4.1.1/13 { #ifdef BOOST_HAS_THREADS lightweight_mutex::scoped_lock lock( mutex() ); #endif block * pb = static_cast
(pv); pb->next = free; free = pb; } } static inline void dealloc(void * pv, std::size_t n) { if(n != size) // class-specific delete called for a derived object { ::operator delete(pv); } else if(pv != 0) // 18.4.1.1/13 { #ifdef BOOST_HAS_THREADS lightweight_mutex::scoped_lock lock( mutex() ); #endif block * pb = static_cast
(pv); pb->next = free; free = pb; } } }; #ifdef BOOST_HAS_THREADS template
lightweight_mutex * allocator_impl
::mutex_init = &allocator_impl
::mutex(); #endif template
freeblock
* allocator_impl
::free = 0; template
freeblock
* allocator_impl
::page = 0; template
unsigned allocator_impl
::last = allocator_impl
::items_per_page; template
struct quick_allocator: public allocator_impl< sizeof(T), boost::alignment_of
::value > { }; } // namespace detail } // namespace boost #endif // #ifndef BOOST_DETAIL_QUICK_ALLOCATOR_HPP_INCLUDED
quick_allocator.hpp
网页地址
文件地址
上一页
38/61
下一页
下载
( 5 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.