Code Monkey home page Code Monkey logo

quqimemorypool's Introduction

内存池MemoryPool

  • 模板类型为class时 使用格式如下
struct hi
{
	hi() {}
	vector<int> a;
	~hi() {}
};
qmem::SingleDataTypeMemoryPool<hi> sd2;
//allocate 获取内存
//自动调用构造函数
hi* qw = sd2.allocate();
//归还内存
sd2.deallocate(qw);
  • 不同内存池之间的性能
{
	//模板类型为class时 使用格式如下
	qmem::SingleDataTypeMemoryPool<hi> sd2;
	//allocate 获取内存
	//自动调用构造函数
	hi* qw = sd2.allocate();
	//归还内存
	sd2.deallocate(qw);
}

{
	//允许单个类型获取内存的内存池,不允许生成数组
	//release 获取内存和释放内存平均耗时 1.597e-08s
	qmem::SingleDataTypeMemoryPool<size_t> sd;
	clock_t start = clock();
	for (size_t i = 0; i < times; ++i)
	{
		a[i] = sd.allocate();
	}
	for (size_t i = 0; i < times; ++i)
	{
		sd.deallocate(a[i]);
	}
	cout << "SingleDataTypeMemoryPool:" << static_cast<long double>(clock() - start) / CLOCKS_PER_SEC / times << '\n';
}

{
	//标准库内存池
	//release 获取内存和释放内存平均耗时 9.122e-08s
	allocator<size_t> stdAllocator;
	clock_t start = clock();
	for (size_t i = 0; i < times; ++i)
	{
		a[i] = stdAllocator.allocate(1);
	}
	for (size_t i = 0; i < times; ++i)
	{
		stdAllocator.deallocate(a[i], 1);
	}
	cout << "allocator:" << static_cast<long double>(clock() - start) / CLOCKS_PER_SEC / times << '\n';
}

quqimemorypool's People

Contributors

quqionfree avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.