本文整理汇总了C++中IOBuf::capacity方法的典型用法代码示例。如果您正苦于以下问题:C++ IOBuf::capacity方法的具体用法?C++ IOBuf::capacity怎么用?C++ IOBuf::capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOBuf
的用法示例。
在下文中一共展示了IOBuf::capacity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buf
BENCHMARK(cloneIntoBenchmark, iters) {
IOBuf buf(IOBuf::CREATE, 10);
IOBuf copy;
while (iters--) {
buf.cloneInto(copy);
folly::doNotOptimizeAway(copy.capacity());
}
}
示例2: sizeof
TEST(IOBuf, move) {
// Default allocate an IOBuf on the stack
IOBuf outerBuf;
char data[] = "foobar";
uint32_t length = sizeof(data);
uint32_t actualCapacity{0};
const void* ptr{nullptr};
{
// Create a small IOBuf on the stack.
// Note that IOBufs created on the stack always use an external buffer.
IOBuf b1(IOBuf::CREATE, 10);
actualCapacity = b1.capacity();
EXPECT_GE(actualCapacity, 10);
EXPECT_EQ(0, b1.length());
EXPECT_FALSE(b1.isShared());
ptr = b1.data();
ASSERT_TRUE(ptr != nullptr);
memcpy(b1.writableTail(), data, length);
b1.append(length);
EXPECT_EQ(length, b1.length());
// Use the move constructor
IOBuf b2(std::move(b1));
EXPECT_EQ(ptr, b2.data());
EXPECT_EQ(length, b2.length());
EXPECT_EQ(actualCapacity, b2.capacity());
EXPECT_FALSE(b2.isShared());
// Use the move assignment operator
outerBuf = std::move(b2);
// Close scope, destroying b1 and b2
// (which are both be invalid now anyway after moving out of them)
}
EXPECT_EQ(ptr, outerBuf.data());
EXPECT_EQ(length, outerBuf.length());
EXPECT_EQ(actualCapacity, outerBuf.capacity());
EXPECT_FALSE(outerBuf.isShared());
}