

A universal thread-safe memory pool
source link: https://www.tuicool.com/articles/hit/63YRVnJ
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ump
A universal thread-safe memory pool. This simple memory pool can be used if following conditions are satisfied:
(1) The memory sizes are some fixed numbers. E.g, 32
, 64
, 128
, etc, not random;
(2) The allocating memory operation is not so cheap, e.g., CUDA.
Example:
#include <cstdlib> #include <iostream> #include "ump.h" int main() { UMP ump{malloc, free}; auto p1 = ump.allocate_memory(100); std::cout << p1 << std::endl; auto p2 = ump.allocate_memory(100); std::cout << p2 << std::endl; ump.free_memory(p1); auto p3 = ump.allocate_memory(100); std::cout << p3 << std::endl; ump.free_memory(p2); ump.free_memory(p3); std::cout << ump.get_used_memory() << std::endl; return 0; }
Build and run it:
$ c++ -g -O2 -Wall main.cpp $ ./a.out 0x55db2b807160 0x55db2b807620 0x55db2b807160 200
Recommend
-
160
Finally Getting the Most out of the Java Thread Pool Eugen Paraschiv September 6, 2017 Develop...
-
26
Node Thread Pool :arrow_double_up: :on: Contents · · · · · · Overview Node...
-
7
A proper thread safe memory cache The Core 2.2 IMemoryCache is in theory thread safe. But if you call GetOrCreateAsync from multiple threads the factory Func will be called multiple times. Whi...
-
6
How to implement a thread pool By popular demand, and at the request of my coworkers, this week’s class was about implementing a simple thread pool using o...
-
8
C++20: Building a Thread-Pool With Coroutines – Cover Image: Coming up wit...
-
6
Description In this episode, Software Engineer, Mike Rousos, joins Rich to go through some ways to diagnose thread pool exhaustion in your .NET apps. Mike discusses and demos a collection of .NET CLI tools and techni...
-
10
How can I detect that a thread pool work item is taking too long? Raymond January 10th, 2022 A customer wants to detect...
-
13
2021 0724: 2021 0824: 2021 0901: 这是遗忘了很久的一篇,一直没有发出来。 今天我的 RSS 表里面出现了一篇写 C++11 线程池的,使得我觉得要清理一下,就找出来,重写了一遍,发了。 说是重写,...
-
7
实例分析Scheduled Thread Pool Executor与Timer的区别 精选 原创 摘要:JDK 1.5开始提供Scheduled...
-
2
8000字详解Thread Pool Executor 精选 原创 摘要:
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK