コード例 #1
0
ファイル: allocator_test.cpp プロジェクト: 3Hren/libcds
        void alloc_all_free_all()
        {
            ALLOC a;

            for ( size_t nPass = 0; nPass < s_nPassCount; ++nPass ) {
                unsigned long long nTotalAllocated = 0;
                char * pHead = a.allocate( sizeof(void *), nullptr );
                CPPUNIT_ASSERT( pHead != nullptr );
                char * pCur = pHead;
                size_t nCurIdx = 0;
                while ( nTotalAllocated < s_nAllocPerPass ) {
                    size_t nSize = m_arrSize[nCurIdx] + sizeof(void *);
                    char * p = a.allocate( nSize, nullptr );
                    CPPUNIT_ASSERT( p != nullptr );
                    memset( p, 0x96, nSize );
                    *((char **) pCur) = p;
                    pCur = p;
                    nTotalAllocated += nSize;
                    if ( ++nCurIdx > s_nArrSizeSize )
                        nCurIdx = 0;
                }
                *((char **) pCur) = nullptr;

                pCur = pHead;
                while ( pCur != nullptr ) {
                    char * pNext = *((char **) pCur);
                    a.deallocate( pCur, 0 );
                    pCur = pNext;
                }
            }
        }
コード例 #2
0
ファイル: allocator_test.cpp プロジェクト: 3Hren/libcds
        void alloc_free()
        {
            ALLOC a;

            for ( size_t nPass = 0; nPass < s_nPassCount; ++nPass ) {
                unsigned long long nTotalAllocated = 0;
                size_t nCurIdx = 0;
                while ( nTotalAllocated < s_nAllocPerPass ) {
                    size_t nSize = m_arrSize[nCurIdx] + 4;
                    char * p = a.allocate( nSize, nullptr );
                    CPPUNIT_ASSERT( p != nullptr );
                    memset( p, 0x96, nSize );
                    nTotalAllocated += nSize;
                    a.deallocate( p, 1 );
                    if ( ++nCurIdx > s_nArrSizeSize )
                        nCurIdx = 0;
                }
            }
        }
コード例 #3
0
ファイル: larson.cpp プロジェクト: 3Hren/libcds
        void test( size_t nThreadCount )
        {
            ALLOC alloc;

            CPPUNIT_MSG( "Thread count=" << nThreadCount );
            CPPUNIT_MSG("Initialize data..." );

            randomGen<unsigned int> rndGen;

            s_nPassPerThread = s_nPassCount / nThreadCount;

            size_t nThread;
            m_aThreadData = new thread_data[ nThreadCount ];
            for ( nThread = 0; nThread < nThreadCount; ++nThread ) {
                thread_data thData
                    = m_aThreadData[nThread]
                    = new char *[ s_nBlocksPerThread ];
                    for ( size_t i = 0; i < s_nBlocksPerThread; ++i ) {
                        thData[i] = reinterpret_cast<char *>(alloc.allocate( rndGen( s_nMinBlockSize, s_nMaxBlockSize ), nullptr ));
                        CPPUNIT_ASSERT( (reinterpret_cast<uintptr_t>(thData[i]) & (ALLOC::alignment - 1)) == 0 );
                    }
            }
            CPPUNIT_MSG("Initializatin done" );

            CppUnitMini::ThreadPool pool( *this );
            pool.add( new Thread<ALLOC>( pool, alloc ), nThreadCount );
            nThread = 0;
            for ( CppUnitMini::ThreadPool::iterator it = pool.begin(); it != pool.end(); ++it )
                static_cast<Thread<ALLOC> *>(*it)->m_arr = m_aThreadData[nThread++];

            cds::OS::Timer    timer;
            pool.run();
            CPPUNIT_MSG( "  Duration=" << pool.avgDuration() );

            for ( nThread = 0; nThread < nThreadCount; ++nThread ) {
                thread_data thData = m_aThreadData[nThread];
                for ( size_t i = 0; i < s_nBlocksPerThread; ++i ) {
                    alloc.deallocate( reinterpret_cast<typename ALLOC::value_type *>(thData[i]), 1 );
                }
                delete [] thData;
            }
            delete [] m_aThreadData;
        }
コード例 #4
0
ファイル: random.cpp プロジェクト: IMCG/CDS
        void test( size_t nThreadCount )
        {
            ALLOC alloc ;

            CPPUNIT_MSG( "Thread count=" << nThreadCount )  ;
            s_nPassPerThread = s_nPassCount / nThreadCount  ;

            CppUnitMini::ThreadPool pool( *this )   ;
            pool.add( new Thread<ALLOC>( pool, alloc ), nThreadCount ) ;

            cds::OS::Timer    timer    ;
            pool.run()  ;
            CPPUNIT_MSG( "  Duration=" << pool.avgDuration() ) ;

            for ( size_t i = 0; i < m_Data.size(); ++i ) {
                if ( m_Data[i].m_pszBlock ) {
                    alloc.deallocate( m_Data[i].m_pszBlock, 1 ) ;
                    m_Data[i].m_pszBlock = NULL ;
                }
            }
        }