当前位置: 首页 > wzjs >正文

做网站 站内搜索引擎如何进行百度推广

做网站 站内搜索引擎,如何进行百度推广,茌平网站制作,怎么做淘宝优惠卷网站程序运行时,通常会频繁地进行内存的分配和释放操作。传统的内存分配方式(如使用new和delete运算符)可能会导致内存碎片的产生,并且每次分配和释放内存都有一定的时间开销。内存池通过在程序启动时一次性分配一大块内存或一次性分配…

程序运行时,通常会频繁地进行内存的分配和释放操作。传统的内存分配方式(如使用new和delete运算符)可能会导致内存碎片的产生,并且每次分配和释放内存都有一定的时间开销。内存池通过在程序启动时一次性分配一大块内存或一次性分配多个对象备用,然后在需要时从使用这些内存。当程序使用完内存后,将其归还给内存池,而不是直接释放回操作系统,以此来提高内存分配的效率并减少内存碎片。

#ifndef MEMORY_POOL_HPP_
#define MEMORY_POOL_HPP_#include <condition_variable>
#include <list>
#include <memory>
#include <queue>
#include <type_traits>
#include <utility>#if __cplusplus < 201103L
#error "This program requires C++11 or a later version to compile."
#elif __cplusplus < 201703L
#include <mutex>
#else
#include <shared_mutex>
#endiftemplate <typename ElementType>
class MemoryPool final {template <typename T, typename = void>struct HasReset : std::false_type {};template <typename T>struct HasReset<T, std::void_t<decltype(std::declval<T>().Reset())>> : std::true_type {};static_assert(HasReset<ElementType>::value, "T must has Reset() function");#if __cplusplus < 201703Lusing mutex       = std::mutex;using lock_guard  = std::lock_guard<std::mutex>;using unique_lock = std::lock_guard<std::mutex>;
#elseusing mutex       = std::shared_mutex;using lock_guard  = std::lock_guard<std::shared_mutex>;using unique_lock = std::lock_guard<std::shared_mutex>;
#endifpublic:using SharedPtr = std::shared_ptr<MemoryPool>;using UniquePtr = std::unique_ptr<MemoryPool>;private:explicit MemoryPool(const std::size_t capacity) : capacity(capacity) {}public:MemoryPool(const MemoryPool &)            = delete;MemoryPool(MemoryPool &&)                 = delete;MemoryPool &operator=(const MemoryPool &) = delete;MemoryPool &operator=(MemoryPool &&)      = delete;~MemoryPool() {lock_guard lck(mu);for (auto *item : this->itemAll) {delete item;}this->itemAll.clear();while (!this->itemAvailable.empty()) {this->itemAvailable.pop();}}template <typename... Args>static std::shared_ptr<MemoryPool> Create(std::size_t capacity, Args &&...args) {auto *poolPtr = new MemoryPool(capacity);for (int32_t i = 0; i < poolPtr->capacity; i++) {auto *itemPtr = new ElementType(std::forward<Args>(args)...);poolPtr->itemAll.push_back(itemPtr);poolPtr->itemAvailable.push(itemPtr);}return std::shared_ptr<MemoryPool>(poolPtr);}bool GetSharedPtr(std::shared_ptr<ElementType> &sharedItemPtr, const int32_t timeout = 0) {unique_lock lck(mu);if (timeout > 0) {this->cv.wait_for(lck, std::chrono::milliseconds(timeout), [this] { return !this->itemAvailable.empty(); });} else {this->cv.wait(lck, [this] { return !this->itemAvailable.empty(); });}if (this->itemAvailable.empty()) {sharedItemPtr = nullptr;return false;}auto *itemPtr = this->itemAvailable.front();this->itemAvailable.pop();sharedItemPtr = std::shared_ptr<ElementType>(itemPtr, [this](ElementType *elementPtr) {elementPtr->Reset();this->itemAvailable.push(elementPtr);this->cv.notify_all();});return true;}private:mutex                     mu;std::condition_variable   cv;std::list<ElementType *>  itemAll;std::queue<ElementType *> itemAvailable;std::size_t               capacity;
};
#endif
http://www.dtcms.com/wzjs/470856.html

相关文章:

  • 做网站规避什么百度收录站长工具
  • 网站中的ppt链接怎么做太原自动seo
  • 宁波住房和城乡建设培训网站扬州整站seo
  • 网站建设时间表301313龙虎榜
  • 梁山网站建设哪家好营销型网站建设哪家好
  • 临平做网站企业网站优化价格
  • 北京企业建设网站成都网站设计公司
  • 自己电脑做服务器搭建网站如何创建个人网页
  • 酷家乐网站做墙裙教程百度广告销售
  • 快速搭建小程序汕头seo收费
  • 肇庆网站制作系统谷歌网站网址
  • 福田网站制作各大搜索引擎入口
  • wordpress 首页logoseo搜索引擎优化试题及答案
  • 上国外网站的host推广app大全
  • 做网站做丝袜美女的能行吗武汉百度推广外包
  • 手机网站建设域名空间做互联网项目怎么推广
  • 网站建设工作会议.企业网站推广有哪些
  • 网站没有备案信息该怎么做小说网站排名免费
  • 做网站工作怀孕2023年8月新冠疫情
  • 网站建设技术杭州谷歌推广
  • 最好的网站统计网络安全
  • 站长网站建设磁力搜索
  • 做的网站上更改内容改怎么百度热度榜搜索趋势
  • 有专门学做衣服网站海外seo推广公司
  • 网站建设补贴乐天seo视频教程
  • 酷炫html5网站海外短视频跨境电商平台是真的吗
  • 陶瓷网站开发背景推广关键词怎么设置
  • 深圳三级分销网站设计制作成都外贸seo
  • 长沙网站建设模板建站模板平台
  • 织梦保险网站源码昆明网络营销