C++ (Qt)struct CBinMatrix { CBinMatrix (int row, int col ) // row = 100000, col = 20 { mColBytes = (col + 7) / 8; mRow = row; mData = new unsigned char[mColBytes * mRow); } ~CBinMatrix( void ) { delete [] mData; } bool Get( int row, int col ) const { unsigned char src = *(mData + row * mColBytes + col / 8); return (src & (1 << (col % 8))) != 0; } bool Set( int row, int col. bool val ) {// напишите по образцу Get } // data size_t mColBytes. mRow; unsigned char * mData;};
C++ (Qt) bool Get( int row, int col ) const { unsigned char src = *(mData + row * mColBytes + col / 8); return (src & (col % 8)) != 0; }
C++ (Qt)*(data + row * mColBytes + col); // data[row][col]
C++ (Qt)Timer timer; CBinMatrix binMatrix(ROWS, COLS); bool d = false; timer.Init(); for (size_t i=0; i<ROWS; i++) { for (size_t k=0; k<COLS; k++) { d += binMatrix.Get(i, k); } } double delta = timer.GetDelta(); qDebug() << d << "BinM " << delta;
C++ (Qt)Timer timer; bool **matrix = new bool*[ROWS]; for (size_t i=0; i<ROWS; i++) matrix[ROWS] = new bool[COLS]; bool d = false; timer.Init(); for (size_t i=0; i<ROWS; i++) { for (size_t k=0; k<COLS; k++) { d += matrix[ROWS][COLS]; } } for (size_t i=0; i<ROWS; i++) delete matrix[i]; delete *matrix; double delta = timer.GetDelta(); qDebug() << d << "bool " << delta;
C++ (Qt) for (size_t i=0; i<ROWS; i++) delete []matrix[i]; delete []matrix;