C++ (Qt)static const int MaxItems = 27; inline int takeAt( quint64 blob, int i ){ Q_ASSERT( i >= 0 && i < MaxItems ); for ( ; i != 0; --i ) blob /= 5; return blob % 5;} inline void putAt( quint64 & blob, int i, int value ){ Q_ASSERT( i >= 0 && i < MaxItems ); Q_ASSERT( value >= 0 && value < 5 ); int values[ MaxItems ] = {0}; int j; for ( j = 0; j < i; j++ ) { values[ j ] = blob % 5; blob /= 5; } blob /= 5; blob *= 5; blob += value; for ( ; j != 0; j-- ) { blob *= 5; blob += values[ j-1 ]; }}
C++ (Qt)#include <cctype>#include <iostream> int main() { const size_t sz = 1024*1024; for ( size_t i = 0; i < sz; ++i ) { new char; } std::cin.get(); return 0;}
C++ (Qt)struct mem_block { struct mem_block* prev; struct mem_block* next; void* ptr; size_t size;};
typedef unsigned char uchar; struct Array3Bits { Array3Bits( size_t num ) : mData(0) { Alloc(num); } ~Array2Bits( void ) { Destroy(); } uchar Get( size_t index ) const { return (mData[index / 2] >> ((index & 1) ? 0 : 4)) & 7; } void Set( size_t index, uchar val ) { uchar & t = mData[index / 2]; if (index & 1) t = (t & 0xF8) | (val & 7); else t = (t & 0x8F) | ((val << 4) & 0x70); } private: void Alloc ( size_t num ) { mData = num ? (new uchar [(num + 1) / 2]) : 0; } void Destroy( void ) { if (mData) delete [] mData; } // data uchar * mData;};