当前位置: 首页>>代码示例>>C++>>正文


C++ ObjectPool::acquireObject方法代码示例

本文整理汇总了C++中ObjectPool::acquireObject方法的典型用法代码示例。如果您正苦于以下问题:C++ ObjectPool::acquireObject方法的具体用法?C++ ObjectPool::acquireObject怎么用?C++ ObjectPool::acquireObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObjectPool的用法示例。


在下文中一共展示了ObjectPool::acquireObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char **args)
{
	ObjectPool<int> pool;
	
	int &a = pool.acquireObject();
	pool.releaseObject(a);
	
	return 0;
}
开发者ID:luoxn28,项目名称:algorithm_data_structure,代码行数:9,代码来源:ObjectPool.cpp

示例2: testRelease

void ObjectPoolTest::testRelease()
{
	ObjectPool<Serial> myPool;
	const size_t numberOfObjectsToRetrieve = 10;

	std::vector<ObjectPool<Serial>::Object> retrievedSerials;
	for (size_t i = 0; i < numberOfObjectsToRetrieve; i++) {
		// Add the retrieved Serial to the vector to keep it 'alive'.
		retrievedSerials.push_back(myPool.acquireObject());
	}
	size_t lastSerialNumber = retrievedSerials.back()->getSerialNumber();
	// Release all objects back to the pool.
	retrievedSerials.clear();

	// The above loop has created ten Serial objects, with serial
	// numbers 0-9, and released all ten Serial objects back to the pool.

	// The next loop first again retrieves ten Serial objects. The serial
	// numbers of these should all be <= lastSerialNumber.
	// The Serial object acquired after that should have a new serial number.

	bool wronglyNewObjectCreated = false;
	for (size_t i = 0; i < numberOfObjectsToRetrieve; i++) {
		auto nextSerial = myPool.acquireObject();
		if (nextSerial->getSerialNumber() > lastSerialNumber) {
			wronglyNewObjectCreated = true;
			break;
		}
		retrievedSerials.push_back(nextSerial);
	}

	// Acquire one more Serial object, which should have a serial
	// number > lastSerialNumber.
	auto anotherSerial = myPool.acquireObject();
	bool newObjectCreated = (anotherSerial->getSerialNumber() > lastSerialNumber);

	Assert::IsFalse(wronglyNewObjectCreated);
	Assert::IsTrue(newObjectCreated);
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:39,代码来源:ObjectPoolTest.cpp

示例3: testExclusivity

void ObjectPoolTest::testExclusivity()
{
	ObjectPool<Serial> myPool;
	const size_t numberOfObjectsToRetrieve = 10;
	std::vector<ObjectPool<Serial>::Object> retrievedSerials;
	std::set<size_t> seenSerialNumbers;

	for (size_t i = 0; i < numberOfObjectsToRetrieve; i++) {
		auto nextSerial = myPool.acquireObject();

		// Add the retrieved Serial to the vector to keep it 'alive',
		// and add the serial number to the set.
		retrievedSerials.push_back(nextSerial);
		seenSerialNumbers.insert(nextSerial->getSerialNumber());
	}

	// Assert that all retrieved serial numbers are different.
	Assert::AreEqual(numberOfObjectsToRetrieve, seenSerialNumbers.size());
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:19,代码来源:ObjectPoolTest.cpp

示例4: testAcquire

void ObjectPoolTest::testAcquire()
{
	ObjectPool<Serial> myPool;
	shared_ptr<Serial> serial = myPool.acquireObject();
	CPPUNIT_ASSERT(serial->getSerialNumber() >= 0);
}
开发者ID:EmuxEvans,项目名称:Woody-Ye-s-Code-Share,代码行数:6,代码来源:ObjectPoolTest.cpp

示例5: testAcquire

void ObjectPoolTest::testAcquire()
{
	ObjectPool<Serial> myPool;
	auto serial = myPool.acquireObject();
	Assert::IsTrue(serial->getSerialNumber() >= 0);
}
开发者ID:sbcalim,项目名称:professional-cpp-4th-ed,代码行数:6,代码来源:ObjectPoolTest.cpp


注:本文中的ObjectPool::acquireObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。