本文整理汇总了C++中Alloc::size方法的典型用法代码示例。如果您正苦于以下问题:C++ Alloc::size方法的具体用法?C++ Alloc::size怎么用?C++ Alloc::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Alloc
的用法示例。
在下文中一共展示了Alloc::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fullFile
void
shafile(const string &baseDir,
const string &file)
{
unsigned char digest[SHA256_DIGEST_LENGTH];
SHA256_CTX c;
string fullFile(prependBaseDir(baseDir, file));
FastOS_File f;
std::ostringstream os;
Alloc buf = Alloc::alloc(65536, MemoryAllocator::HUGEPAGE_SIZE, 0x1000);
f.EnableDirectIO();
bool openres = f.OpenReadOnly(fullFile.c_str());
if (!openres) {
LOG(error, "Could not open %s for sha256 checksum", fullFile.c_str());
LOG_ABORT("should not be reached");
}
int64_t flen = f.GetSize();
int64_t remainder = flen;
SHA256_Init(&c);
while (remainder > 0) {
int64_t thistime =
std::min(remainder, static_cast<int64_t>(buf.size()));
f.ReadBuf(buf.get(), thistime);
SHA256_Update(&c, buf.get(), thistime);
remainder -= thistime;
}
f.Close();
SHA256_Final(digest, &c);
for (unsigned int i = 0; i < SHA256_DIGEST_LENGTH; ++i) {
os.width(2);
os.fill('0');
os << std::hex << static_cast<unsigned int>(digest[i]);
}
LOG(info,
"SHA256(%s)= %s",
file.c_str(),
os.str().c_str());
}
示例2: tmpA
{
void * tmpA(a.get());
void * tmpB(b.get());
EXPECT_EQUAL(4096ul, a.size());
EXPECT_EQUAL(8192ul, b.size());
std::swap(a, b);
EXPECT_EQUAL(4096ul, b.size());
EXPECT_EQUAL(8192ul, a.size());
EXPECT_EQUAL(tmpA, b.get());
EXPECT_EQUAL(tmpB, a.get());
}
TEST("test basics") {
{
Alloc h = Alloc::allocHeap(100);
EXPECT_EQUAL(100u, h.size());
EXPECT_TRUE(h.get() != nullptr);
}
{
EXPECT_EXCEPTION(Alloc::allocAlignedHeap(100, 7), IllegalArgumentException, "Alloc::allocAlignedHeap(100, 7) does not support 7 alignment");
Alloc h = Alloc::allocAlignedHeap(100, 1024);
EXPECT_EQUAL(100u, h.size());
EXPECT_TRUE(h.get() != nullptr);
}
{
Alloc h = Alloc::allocMMap(100);
EXPECT_EQUAL(4096u, h.size());
EXPECT_TRUE(h.get() != nullptr);
}
{
Alloc a = Alloc::allocHeap(4096), b = Alloc::allocHeap(8192);