本文整理汇总了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;
//.........这里部分代码省略.........