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


C++ Page::alloc方法代码示例

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


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

示例1: checkPageKill

void checkPageKill()
{
    cerr << fmtTitle("kill", '.') << endl;

    typedef BlockPage<Policy> Page;
    array<void*, Page::NumBlocks> blocks;

    auto& log = Page::log;

    locklessCheck(createPage<Policy>()->kill(), log);

    {
        Page* page = createPage<Policy>();

        for (size_t i = 0; i < Page::NumBlocks; ++i)
            blocks[i] = page->alloc();

        locklessCheck(!page->kill(), log);

        for (size_t i = 0; i < Page::NumBlocks; ++i)
            locklessCheckEq(
                    page->free(blocks[i]), i == Page::NumBlocks - 1, log);
    }

    {
        Page* page = createPage<Policy>();

        for (size_t i = 0; i < Page::NumBlocks; ++i)
            blocks[i] = page->alloc();

        for (size_t i = 0; i < Page::NumBlocks / 2; ++i)
            locklessCheckEq(
                    page->free(blocks[i]), i == Page::NumBlocks - 1, log);

        locklessCheck(!page->kill(), log);

        for (size_t i = Page::NumBlocks / 2; i < Page::NumBlocks; ++i)
            locklessCheckEq(
                    page->free(blocks[i]), i == Page::NumBlocks - 1, log);
    }

    {
        Page* page = createPage<Policy>();

        for (size_t i = 0; i < Page::NumBlocks; ++i)
            blocks[i] = page->alloc();

        for (size_t i = 0; i < Page::NumBlocks; ++i)
            locklessCheck(!page->free(blocks[i]), log);

        locklessCheck(page->kill(), log);
    }
}
开发者ID:RAttab,项目名称:lockless,代码行数:53,代码来源:alloc_test.cpp

示例2: checkPageAlloc

void checkPageAlloc()
{
    cerr << fmtTitle("alloc", '.') << endl;

    typedef BlockPage<Policy> Page;

    Page* page = createPage<Policy>();
    auto& log = Page::log;

    array<void*, Page::NumBlocks> blocks;

    for (size_t i = 0; i < Page::NumBlocks; ++i) {
        locklessCheck(page->hasFreeBlock(), log);

        void* block = page->alloc();
        fillBlock<Policy>(block, i);

        page->free(blocks[i] = block);

        if (!i) {
            locklessCheckEq(
                    uintptr_t(page) + (Page::MetadataBlocks * Policy::BlockSize),
                    uintptr_t(blocks[0]),
                    log);
        }
        else {
            locklessCheckGt(blocks[i], page, log);
            locklessCheckLe(
                    uintptr_t(blocks[i]) + Policy::BlockSize,
                    uintptr_t(page) + Policy::PageSize,
                    log);

            locklessCheckEq(
                    uintptr_t(blocks[i-1]) + Policy::BlockSize,
                    uintptr_t(blocks[i]),
                    log);
        }

        locklessCheckEq(page, Page::pageForBlock(blocks[i]), log);
    }

    for (size_t iteration = 0; iteration < 2; ++iteration) {
        for (size_t i = 0; i < Page::NumBlocks; ++i)
            locklessCheckEq(blocks[i], page->alloc(), log);

        for (size_t i = 0; i < Page::NumBlocks; ++i)
            page->free(blocks[i]);
    }

    locklessCheck(page->kill(), log);
}
开发者ID:RAttab,项目名称:lockless,代码行数:51,代码来源:alloc_test.cpp

示例3: multipleAllocFreeTest

  void multipleAllocFreeTest() {
    int i;
    Page *page;
    uint32_t ps = ((LocalEnvironment *)m_env)->config().page_size_bytes;

    for (i = 0; i < 10; i++) {
      page = new Page(((LocalEnvironment *)m_env)->device());
      page->alloc(0, ps);
      /* i+2 since we need 1 page for the header page and one page
       * for the root page */
      if (!m_inmemory)
        REQUIRE(page->get_address() == (i + 2) * ps);
      delete page;
    }
  }
开发者ID:jpexltd,项目名称:upscaledb,代码行数:15,代码来源:page.cpp

示例4: checkPageFull

void checkPageFull()
{
    cerr << fmtTitle("full", '.') << endl;

    typedef BlockPage<Policy> Page;

    Page* page = createPage<Policy>();

    array<void*, Page::NumBlocks> blocks;
    for (size_t i = 0; i < Page::NumBlocks; ++i)
        page->free(blocks[i] = page->alloc());

    for (size_t k = 1; k < Page::NumBlocks; ++k) {
        for (size_t i = 0; i < Page::NumBlocks; ++i)
            page->alloc();

        locklessCheck(!page->hasFreeBlock(), NullLog);

        for (size_t i = 0; i < Page::NumBlocks; i += k)
            page->free(blocks[i]);

        locklessCheck(page->hasFreeBlock(), NullLog);

        for (size_t i = 0; i < Page::NumBlocks; i += k)
            page->alloc();

        locklessCheck(!page->hasFreeBlock(), NullLog);

        for (size_t i = 0; i < Page::NumBlocks; ++i)
            page->free(blocks[i]);

        locklessCheck(page->hasFreeBlock(), NullLog);
    }

    locklessCheck(page->kill(), NullLog);
}
开发者ID:RAttab,项目名称:lockless,代码行数:36,代码来源:alloc_test.cpp

示例5: allocFreeTest

 void allocFreeTest() {
   Page *page;
   page = new Page(((LocalEnvironment *)m_env)->device());
   page->alloc(0, 1024);
   delete page;
 }
开发者ID:jpexltd,项目名称:upscaledb,代码行数:6,代码来源:page.cpp


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