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


C++ Tracker::assign_allocated_record_to_uninitialized方法代码示例

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


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

示例1: test_shared_alloc


//.........这里部分代码省略.........
      while ( 0 != ( r[i] = static_cast< RecordMemS * >( RecordBase::decrement( r[i] ) ) ) ) {
#ifdef KOKKOS_DEBUG
        if ( r[i]->use_count() == 1 ) RecordBase::is_sane( r[i] );
#endif
      }
    });
  }

  {
    int destroy_count = 0;
    SharedAllocDestroy counter( &destroy_count );

    Kokkos::parallel_for( range, [=] ( size_t i ) {
      char name[64];
      sprintf( name, "test_%.2d", int( i ) );

      RecordFull * rec = RecordFull::allocate( s, name, size * ( i + 1 ) );

      rec->m_destroy = counter;

      r[i] = rec;
      h[i] = Header::get_header( r[i]->data() );

      ASSERT_EQ( r[i]->use_count(), 0 );

      for ( size_t j = 0; j < ( i / 10 ) + 1; ++j ) RecordBase::increment( r[i] );

      ASSERT_EQ( r[i]->use_count(), ( i / 10 ) + 1 );
      ASSERT_EQ( r[i], RecordMemS::get_record( r[i]->data() ) );
    });

#ifdef KOKKOS_DEBUG
    RecordBase::is_sane( r[0] );
#endif

    Kokkos::parallel_for( range, [=] ( size_t i ) {
      while ( 0 != ( r[i] = static_cast< RecordMemS * >( RecordBase::decrement( r[i] ) ) ) ) {
#ifdef KOKKOS_DEBUG
        if ( r[i]->use_count() == 1 ) RecordBase::is_sane( r[i] );
#endif
      }
    });

    ASSERT_EQ( destroy_count, int( N ) );
  }

  {
    int destroy_count = 0;

    {
      RecordFull * rec = RecordFull::allocate( s, "test", size );

      // ... Construction of the allocated { rec->data(), rec->size() }

      // Copy destruction function object into the allocation record.
      rec->m_destroy = SharedAllocDestroy( & destroy_count );

      ASSERT_EQ( rec->use_count(), 0 );

      // Start tracking, increments the use count from 0 to 1.
      Tracker track;

      track.assign_allocated_record_to_uninitialized( rec );

      ASSERT_EQ( rec->use_count(), 1 );
      ASSERT_EQ( track.use_count(), 1 );

      // Verify construction / destruction increment.
      for ( size_t i = 0; i < N; ++i ) {
        ASSERT_EQ( rec->use_count(), 1 );

        {
          Tracker local_tracker;
          local_tracker.assign_allocated_record_to_uninitialized( rec );
          ASSERT_EQ( rec->use_count(), 2 );
          ASSERT_EQ( local_tracker.use_count(), 2 );
        }

        ASSERT_EQ( rec->use_count(), 1 );
        ASSERT_EQ( track.use_count(), 1 );
      }

      Kokkos::parallel_for( range, [=] ( size_t i ) {
        Tracker local_tracker;
        local_tracker.assign_allocated_record_to_uninitialized( rec );
        ASSERT_GT( rec->use_count(), 1 );
      });

      ASSERT_EQ( rec->use_count(), 1 );
      ASSERT_EQ( track.use_count(), 1 );

      // Destruction of 'track' object deallocates the 'rec' and invokes the destroy function object.
    }

    ASSERT_EQ( destroy_count, 1 );
  }

#endif /* #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST ) */

}
开发者ID:Pakketeretet2,项目名称:lammps,代码行数:101,代码来源:TestSharedAlloc.hpp


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