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


C++ ObjectPool类代码示例

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


在下文中一共展示了ObjectPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: test1

void test1()
{
    ObjectPool<SmallObject> op;
    SmallObject* s = op.get();
    op.put(s);
    s = op.get();
    s = op.get();
    s = op.get();
    s = op.get();

    printf("++++++++++++++++\n");
}
开发者ID:jianglutian,项目名称:GameServer,代码行数:12,代码来源:objectpool.cpp

示例3: TEST_F

TEST_F(ObjectPoolTest, MovableObjectPool) {
  ObjectPool<int> to;

  // Verify a move works correctly when an object has been checked out:
  {
    ObjectPool<int> from;
    auto original = from.Wait();
    to = std::move(from);
  }

  // Now verify that the pooled object returned home to the right place:
  ASSERT_EQ(1UL, to.GetCached()) << "Object pool move operation did not correctly relay checked out types";
}
开发者ID:jdiego,项目名称:autowiring,代码行数:13,代码来源:ObjectPoolTest.cpp

示例4: auxCacheForSrcPhrase

void LexicalReorderingTableTree::auxCacheForSrcPhrase(const Phrase& f)
{
  if(m_FactorsE.empty()) {
    //f is all of key...
    Candidates cands;
    m_Table->GetCandidates(MakeTableKey(f,Phrase(ARRAY_SIZE_INCR)),&cands);
    m_Cache[MakeCacheKey(f,Phrase(ARRAY_SIZE_INCR))] = cands;
  } else {
    ObjectPool<PPimp>     pool;
    PPimp* pPos  = m_Table->GetRoot();
    //1) goto subtree for f
    for(size_t i = 0; i < f.GetSize() && 0 != pPos && pPos->isValid(); ++i) {
      /* old code
      pPos = m_Table.Extend(pPos, auxClearString(f.GetWord(i).ToString(m_FactorsF)), SourceVocId);
      */
      pPos = m_Table->Extend(pPos, f.GetWord(i).GetString(m_FactorsF, false), SourceVocId);
    }
    if(0 != pPos && pPos->isValid()) {
      pPos = m_Table->Extend(pPos, PrefixTreeMap::MagicWord);
    }
    if(0 == pPos || !pPos->isValid()) {
      return;
    }
    //2) explore whole subtree depth first & cache
    std::string cache_key = auxClearString(f.GetStringRep(m_FactorsF)) + "|||";

    std::vector<State> stack;
    stack.push_back(State(pool.get(PPimp(pPos->ptr()->getPtr(pPos->idx),0,0)),""));
    Candidates cands;
    while(!stack.empty()) {
      if(stack.back().pos->isValid()) {
        LabelId w = stack.back().pos->ptr()->getKey(stack.back().pos->idx);
        std::string next_path = stack.back().path + " " + m_Table->ConvertWord(w,TargetVocId);
        //cache this
        m_Table->GetCandidates(*stack.back().pos,&cands);
        if(!cands.empty()) {
          m_Cache[cache_key + auxClearString(next_path)] = cands;
        }
        cands.clear();
        PPimp* next_pos = pool.get(PPimp(stack.back().pos->ptr()->getPtr(stack.back().pos->idx),0,0));
        ++stack.back().pos->idx;
        stack.push_back(State(next_pos,next_path));
      } else {
        stack.pop_back();
      }
    }
  }
}
开发者ID:lolobaro,项目名称:mosesdecoder-stackrescore,代码行数:48,代码来源:LexicalReorderingTable.cpp

示例5: _g_objPool

namespace KBEngine
{
static ObjectPool<MemoryStream> _g_objPool("MemoryStream");
//-------------------------------------------------------------------------------------
ObjectPool<MemoryStream>& MemoryStream::ObjPool()
{
	return _g_objPool;
}

//-------------------------------------------------------------------------------------
void MemoryStream::destroyObjPool()
{
	DEBUG_MSG(boost::format("MemoryStream::destroyObjPool(): size %1%.\n") % 
		_g_objPool.size());

	_g_objPool.destroy();
}

//-------------------------------------------------------------------------------------
MemoryStream::SmartPoolObjectPtr MemoryStream::createSmartPoolObj()
{
	return SmartPoolObjectPtr(new SmartPoolObject<MemoryStream>(ObjPool().createObject(), _g_objPool));
}

//-------------------------------------------------------------------------------------
} 
开发者ID:MonsterCalvin,项目名称:kbengine,代码行数:26,代码来源:memorystream.cpp

示例6: _g_objPool

namespace KBEngine
{
static ObjectPool<MemoryStream> _g_objPool("MemoryStream");
//-------------------------------------------------------------------------------------
ObjectPool<MemoryStream>& MemoryStream::ObjPool()
{
	return _g_objPool;
}

//-------------------------------------------------------------------------------------
void MemoryStream::destroyObjPool()
{
	DEBUG_MSG(fmt::format("MemoryStream::destroyObjPool(): size {}.\n", 
		_g_objPool.size()));

	_g_objPool.destroy();
}

//-------------------------------------------------------------------------------------
MemoryStream::SmartPoolObjectPtr MemoryStream::createSmartPoolObj()
{
	return SmartPoolObjectPtr(new SmartPoolObject<MemoryStream>(ObjPool().createObject(), _g_objPool));
}

//-------------------------------------------------------------------------------------
size_t MemoryStream::getPoolObjectBytes()
{
	size_t bytes = sizeof(rpos_) + sizeof(wpos_) + data_.size();
	return bytes;
}

//-------------------------------------------------------------------------------------
} 
开发者ID:321543223,项目名称:kbengine,代码行数:33,代码来源:memorystream.cpp

示例7: main

int main() {
  ObjectPool<int32_t, 128, false> pool;

  int32_t* a = pool.fetch();
  int32_t* b = pool.fetch();
  int32_t* c = pool.fetch();
  int32_t* d = pool.fetch();

  pool.release(b);
  int32_t* e = pool.fetch();

  fprintf(stdout, "fetch() %p\n", a);
  fprintf(stdout, "fetch() %p\n", b);
  fprintf(stdout, "fetch() %p\n", c);
  fprintf(stdout, "fetch() %p\n", d);
  fprintf(stdout, "fetch() %p\n", e);
  return 0;
}
开发者ID:shindavid,项目名称:hunl,代码行数:18,代码来源:main.cpp

示例8: 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

示例9: destroyObjPool

//-------------------------------------------------------------------------------------
void MemoryStream::destroyObjPool()
{
	DEBUG_MSG(boost::format("MemoryStream::destroyObjPool(): size %1%.\n") % 
		_g_objPool.size());

	_g_objPool.destroy();
}
开发者ID:MonsterCalvin,项目名称:kbengine,代码行数:8,代码来源:memorystream.cpp

示例10: destroyObjPool

//-------------------------------------------------------------------------------------
void Bundle::destroyObjPool()
{
	DEBUG_MSG(fmt::format("Bundle::destroyObjPool(): size {}.\n", 
		_g_objPool.size()));

	_g_objPool.destroy();
}
开发者ID:aabbox,项目名称:kbengine,代码行数:8,代码来源:bundle.cpp

示例11: runtime_error

      void
      add (uint32_t id, char side, uint32_t price, uint32_t size)
      {
        if (orders.end () != orders.find (id, OrderIdHasher (), OrderIdEqual ()))
          {
            throw std::runtime_error ("duplicate add");
          }

        AggregateOrders::iterator found = aggregateOrders.find (std::make_pair (side, price), AggregateOrderLess ());

        if (found == aggregateOrders.end ())
          {
            AggregateOrder *a = aggregateOrderPool.construct (boost::in_place (side, price));
            found = aggregateOrders.insert (*a).first;
          }

        assert(aggregateOrders.end () != found);

        Order *order = orderPool.construct (boost::in_place (id, boost::ref (*found)));
        assert(order);

        bool orderInserted __attribute__((unused)) = orders.insert (*order).second;
        assert(orderInserted);

        order->size = size;
        order->aggregateOrder.size += size;

        assert(order->size);
        assert(order->aggregateOrder.size);
      }
开发者ID:jamesetaylor,项目名称:cpp,代码行数:30,代码来源:OrderBook.hpp

示例12: destroyObjPool

//-------------------------------------------------------------------------------------
void UDPPacketReceiver::destroyObjPool()
{
	DEBUG_MSG(boost::format("UDPPacketReceiver::destroyObjPool(): size %1%.\n") % 
		_g_objPool.size());

	_g_objPool.destroy();
}
开发者ID:fengqk,项目名称:kbengine,代码行数:8,代码来源:udp_packet_receiver.cpp

示例13: destroyObjPool

//-------------------------------------------------------------------------------------
void UDPPacketReceiver::destroyObjPool()
{
	DEBUG_MSG(fmt::format("UDPPacketReceiver::destroyObjPool(): size {}.\n", 
		_g_objPool.size()));

	_g_objPool.destroy();
}
开发者ID:Eayon,项目名称:kbengine,代码行数:8,代码来源:udp_packet_receiver.cpp

示例14: destroyObjPool

//-------------------------------------------------------------------------------------
void TCPPacket::destroyObjPool()
{
	DEBUG_MSG(fmt::format("TCPPacket::destroyObjPool(): size {}.\n", 
		_g_objPool.size()));

	_g_objPool.destroy();
}
开发者ID:Weooh,项目名称:kbengine,代码行数:8,代码来源:tcp_packet.cpp

示例15: destroyObjPool

//-------------------------------------------------------------------------------------
void MemoryStream::destroyObjPool()
{
	DEBUG_MSG(fmt::format("MemoryStream::destroyObjPool(): size {}.\n", 
		_g_objPool.size()));

	_g_objPool.destroy();
}
开发者ID:321543223,项目名称:kbengine,代码行数:8,代码来源:memorystream.cpp


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