本文整理汇总了C++中NValue::allocateObjectFromPool方法的典型用法代码示例。如果您正苦于以下问题:C++ NValue::allocateObjectFromPool方法的具体用法?C++ NValue::allocateObjectFromPool怎么用?C++ NValue::allocateObjectFromPool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NValue
的用法示例。
在下文中一共展示了NValue::allocateObjectFromPool方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UniqueEngineBuilder
TEST_F(TableTupleTest, VolatilePoolBackedTuple) {
UniqueEngine engine = UniqueEngineBuilder().build();
Pool pool;
// A schema with
// - one fixed size column
// - one inlined variable-length column
// - one non-inlined variable-length column
ScopedTupleSchema schema{Tools::buildSchema(VALUE_TYPE_BIGINT,
std::make_pair(VALUE_TYPE_VARCHAR, 12),
std::make_pair(VALUE_TYPE_VARCHAR, 256))};
PoolBackedTupleStorage poolBackedTuple;
poolBackedTuple.init(schema.get(), &pool);
poolBackedTuple.allocateActiveTuple();
TableTuple &tuple = poolBackedTuple;
Tools::setTupleValues(&tuple, int64_t(0), "foo", "foo bar");
// Pool-backed tuples are used as "scratch areas" so their data is
// frequently mutated. NValues that reference them could have
// their data changed.
//
// Non-inlined data is not volatile though.
ASSERT_TRUE(tuple.inlinedDataIsVolatile());
ASSERT_FALSE(tuple.nonInlinedDataIsVolatile());
NValue nv = tuple.getNValue(0);
ASSERT_FALSE(nv.getVolatile());
nv = tuple.getNValue(1);
ASSERT_TRUE(nv.getVolatile());
// After the NValue is made to be non-inlined (copied to temp string pool)
// it is no longer volatile
nv.allocateObjectFromPool();
ASSERT_FALSE(nv.getVolatile());
nv = tuple.getNValue(2);
ASSERT_FALSE(nv.getVolatile());
}
示例2: iterTuple
//.........这里部分代码省略.........
TableTuple tuple = ltt->tempTuple();
ASSERT_EQ(0, lttBlockCache->numPinnedEntries());
const int NUM_TUPLES = 500;
// Attempt to insert enough rows so that we have more than one
// block in this table.
// inline data:
// 136000 (500 * 272)
//
// Four kinds of non-inlined strings:
// NULL 0 (125 * 0)
// empty string 1500 (125 * 12, StringRef and length prefix)
// half string 3126500 (125 * (25000 + 12))
// whole string 6251500 (125 * (50000 + 12))
//
// Total --> 9515500
//
// LTT blocks are 8MB so this data should use two blocks.
for (int64_t i = 0; i < NUM_TUPLES; ++i) {
Tools::setTupleValues(&tuple,
i,
0.5 * i,
0.5 * i + 1,
0.5 * i + 2,
Tools::toDec(0.5 * i),
Tools::toDec(0.5 * i + 1),
Tools::toDec(0.5 * i + 2),
getStringValue(INLINE_LEN, i),
getStringValue(INLINE_LEN, i + 1),
getStringValue(INLINE_LEN, i + 2),
getStringValue(NONINLINE_LEN, i));
ASSERT_TRUE(tuple.inlinedDataIsVolatile());
ASSERT_FALSE(tuple.nonInlinedDataIsVolatile());
ltt->insertTuple(tuple);
}
// The block we were inserting into will be pinned
ASSERT_EQ(1, lttBlockCache->numPinnedEntries());
// Indicate that we are done inserting...
ltt->finishInserts();
// Block is now unpinned
ASSERT_EQ(0, lttBlockCache->numPinnedEntries());
ASSERT_EQ(2, ltt->allocatedBlockCount());
{
TableIterator iter = ltt->iterator();
TableTuple iterTuple(ltt->schema());
int64_t i = 0;
while (iter.next(iterTuple)) {
boost::optional<std::string> inlineStr0 = getStringValue(INLINE_LEN, i);
boost::optional<std::string> inlineStr1 = getStringValue(INLINE_LEN, i + 1);
boost::optional<std::string> inlineStr2 = getStringValue(INLINE_LEN, i + 2);
boost::optional<std::string> nonInlineStr = getStringValue(NONINLINE_LEN, i);
assertTupleValuesEqual(&iterTuple,
i,
0.5 * i,
0.5 * i + 1,
0.5 * i + 2,
Tools::toDec(0.5 * i),
Tools::toDec(0.5 * i + 1),
Tools::toDec(0.5 * i + 2),
inlineStr0,
inlineStr1,
inlineStr2,
nonInlineStr);
// Check volatility of inserted values
NValue nv = iterTuple.getNValue(0);
ASSERT_FALSE(nv.getVolatile()); // bigint
nv = iterTuple.getNValue(7); // inlined varchar
ASSERT_TRUE(nv.getVolatile());
// It can be made non-volatile by allocating in a pool:
nv.allocateObjectFromPool();
ASSERT_FALSE(nv.getVolatile());
ASSERT_EQ(0, Tools::nvalueCompare(inlineStr0, nv));
nv = iterTuple.getNValue(10); // non-inlined varchar
ASSERT_TRUE(nv.getVolatile());
// It can be made non-volatile by allocating in a pool:
nv.allocateObjectFromPool();
ASSERT_FALSE(nv.getVolatile());
ASSERT_EQ(0, Tools::nvalueCompare(nonInlineStr, nv));
++i;
}
ASSERT_EQ(500, i);
}
ltt->deleteAllTempTuples();
ASSERT_EQ(0, lttBlockCache->totalBlockCount());
ASSERT_EQ(0, lttBlockCache->allocatedMemory());
}