Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

因为删除器bug无法二次Get,且unordered_map析构时候有未定义行为 #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fanghaos
Copy link

ObjectPool<BigObject> pool;
pool.Init(2);//初始化对象池,初始创建2个
{
	auto p = pool.Get();
	PrintBigObject(p, "p");
	auto p2 = pool.Get();
	PrintBigObject(p2, "p2");
}**//出了作用域之后,对象池返回出的对象又会自动回收。但是删除器调用时,重载放入map中的智能指针的删除器是默认删除器。**

{
	auto p = pool.Get();
	auto p2 = pool.Get();
	PrintBigObject(p, "p");
	PrintBigObject(p2, "p2");
}//这里结束之后,两个对象就delete了。

{
	//对象池支持重载构造函数!map中现在有4个元素
	pool.Init(2, 1);
	auto p4 = pool.Get<int>();
	PrintBigObject(p4, "p4");
}

{
	//再多加两个元素
	pool.Init(2, 1, 2);
	auto p5 = pool.Get<int, int>();
	PrintBigObject(p5, "p4");
}

并且,在pool的map析构时候,调用的删除器尝试在map中重新emplace。VS2017测试出若干hang。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant