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


C++ SharedBuffer::capacity方法代码示例

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


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

示例1: main

// ============================================================================
//  main
// ============================================================================
int main(int argc, char* argv[])
{
  yat::Message * m = 0;
  
  YAT_LOG_STATIC("Instanciating Task...");
	
  Consumer * dt = new Consumer(kLO_WATER_MARK, kHI_WATER_MARK);
  
  YAT_LOG_STATIC("Starting Task...");
	
  try
  {
    dt->go(2000); 
  }
  catch (const yat::Exception&)
  {
    YAT_LOG_STATIC("yat exception caught - could not start task. aborting...");
    dt->exit();
    return 0;
  }
  catch (...)
  {
    YAT_LOG_STATIC("unknown exception caught - could not start task. aborting...");
    dt->exit();
    return 0;
  }

 /*
  for (size_t i = 0; i < kNUM_MSGS; i++)
  {
    try
    {
      //- post msg to consumer
      dt->post(new yat::Message(kDUMMY_MSG), kPOST_MSG_TMO);

      //- simulate some time consuming activity
      yat::ThreadingUtilities::sleep(0, 100000);
    }
    catch (const std::bad_alloc&)
    {
      YAT_LOG_STATIC("std::bad_alloc except. caught - could not post msg#" << i);
    }
    catch (const yat::Exception&)
    {
      YAT_LOG_STATIC("tango except. caught - could not post msg#" << i);
    }
    catch (...)
    {
      YAT_LOG_STATIC("unknown except. caught - could not post msg#" << i);
    }
  }
*/
 
  yat::Buffer<double> data(kNUM_MSGS);
  for ( size_t i = 0; i < kNUM_MSGS; i++ )
    data[i] = 1. * i;
  data.force_length(kNUM_MSGS);
  
  for (size_t i = 0; i < kNUM_MSGS; i++)
  {
    try
    {
      SharedBuffer* sb = new SharedBuffer();
      sb->capacity(i + 1);
      sb->memcpy(data.base(), i + 1);
      std::cout << "SharedBuffer* sb.length = " << sb->length() << std::endl;
      dt->post(kDATA_MSG, sb->duplicate(), false);
      sb->release();
      //- simulate some time consuming activity
      yat::ThreadingUtilities::sleep(0, 100000);
    }
    catch (const std::bad_alloc&)
    {
      YAT_LOG_STATIC("std::bad_alloc except. caught - could not post msg#" << i);
    }
    catch (const yat::Exception&)
    {
      YAT_LOG_STATIC("tango except. caught - could not post msg#" << i);
    }
    catch (...)
    {
      YAT_LOG_STATIC("unknown except. caught - could not post msg#" << i);
    }
  }
  
  try
  {
    dt->exit();
  }
  catch (const yat::Exception&)
  {
    YAT_LOG_STATIC("tango except. caught - could stop task. aborting...");
  }
  catch (...)
  {
    YAT_LOG_STATIC("unknown except. caught - could stop task. aborting...");
    return 0;
//.........这里部分代码省略.........
开发者ID:srgblnch,项目名称:yat,代码行数:101,代码来源:main.cpp


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