Like Tree1Likes
  • 1 Post By manasij7479

most efficient way of displaying a *HUGE* boolean array

This is a discussion on most efficient way of displaying a *HUGE* boolean array within the C++ Programming forums, part of the General Programming Boards category; Should I go for the command line display via cout or printf ? or would using simple graphics libraries be ...

  1. #1
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498

    most efficient way of displaying a *HUGE* boolean array

    Should I go for the command line display via cout or printf ?
    or would using simple graphics libraries be better(&&faster??) ?
    btw..I was trying to implement a Conway's Game of Life program..with the simple rules..
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Why are you asking about the boolean only? Because it sounds like you would care that this is a boolean array.

    There are some methods to optimize boolean array operations (like in special case of vector - vector<bool>), but when it comes to "displaying", it will not matter, since most of the execution time will be spent on displaying (drawing) itself.

    You should not ask about displaying boolean arrays, but about displaying anything in general, if I understand.
    I never put signature, but I decided to make an exception.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    How big is your game grid?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    I am thinking of making it grow on demand.
    Else a toroidal 100x100.

    displaying anything in general
    for boolean ...maybe the matrix can exactly fit into an implementation of some display function of some graphics library..._.But my knowledge in graphics...is yet very immature.. ..so I can't decide for sure..
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,533
    Well if you can manually cope with creating a console with a suitable font/size, then you should be able to get that kind of resolution just by printing using cout.

    As for graphics, you need to say which OS/Compiler you're using. There's just too much choice to even hazard a guess as to where you might start.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    o..sorry.. It is Linux Mint(Debian)... && gcc-4.6
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    58
    I don't know about printing, but this should not matter much. In terms of storing a matrix of Boolean consider creating an array of unsigned in of size the number of columns in the matrix. Each row can than be represented by an integer in binary representation. You have to check any bit of the integer to get the value in the column of the matrix. This is what i did (assuming a square array but this is easily changed)

    Code:
    #include <iostream>
    
    // BIT MANIPULATIONS
    #define BOOL(x) ( !(!(x)) )
    #define BIT_TEST( arg , pos ) BOOL( (arg)&(1L << (pos)) )
    #define BIT_FLIP( arg , pos ) ( (arg)^(1L << (pos)) )
    
    inline
    unsigned int BIT_SUM( unsigned int v )
    {
    	unsigned int sum;
    	unsigned int tmp = v;
    
    	tmp = tmp - ( ( tmp >> 1 ) & 0x55555555 );
    	tmp = ( tmp & 0x33333333 ) + (( tmp >> 2 ) & 0x33333333 );
    	sum = ( ( tmp + ( tmp >> 4 ) & 0xF0F0F0F ) * 0x1010101 ) >> 24;
    	return( sum );
    }
    
    int main()
    {
    	const unsigned column = 10;
    	unsigned int row[ column ] = {column};
    
    	// FILL ARRAY TO TEST, JUST ANYTHING
    	for( int i = column; i --; ) { row[ i ] = i; }
    
    	// READ AND PRINT VALUES
    	for( int i = column; i --; ) {
    	printf( "%u : " , row[ i ] );
    		for( int j = column; j --; ) {
    			printf( "%u " , BIT_TEST( row[ i ], j ) );
    		}
    	printf( " : %u \n" , BIT_SUM( i ) );
    	}
    	
    	// READ FLIP AND PRINT VALUES
    	for( int i = column; i --; ) {
    	printf( "%u : " , row[ i ] );
    		for( int j = column; j --; ) {
    			printf( "%u " , BIT_TEST( BIT_FLIP( row[ i ], j ), j ) );
    		}
    	printf( " : %u \n" , BIT_SUM( i ) );
    	}
    				
    	return 0;
    }

  8. #8
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    What advantage would this low level approach to storage have over creating a (x*y) sized boolean array?
    I (maybe erroneously) understand that they are exactly same as far as the computer is concerned...but increases the effort needed by the user...
    Salem likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  9. #9
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Quote Originally Posted by manasij7479 View Post
    What advantage would this low level approach to storage have over creating a (x*y) sized boolean array?
    I (maybe erroneously) understand that they are exactly same as far as the computer is concerned...but increases the effort needed by the user...
    I haven't looked into this code much, but he probably wants to use one bit per boolean. He forgot that this is already implemented in the STL:

    bitset - C++ Reference

    for fixed size. For dynamic, use vector<bool>.

    Also, wtf is this:

    Code:
    #define BOOL(x) ( !(!(x)) )
    Firstly, it collides with WinAPI (he might want to move to Windows?) and possibly with other implementations. To be honest, this is the first time I see someone trying to convert int to bool this way.

    Code:
    static_cast<bool>(x)
    looks better to me.
    I never put signature, but I decided to make an exception.

  10. #10
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    I heard that the use of vector<bool> wastes memory,time..everything(!) ....but never found out a reason other than that they are high level and doesn't do anything concerning bits.... Is there anything except that?
    As for storage, I created my own class storing the bools with all the necessary means for dynamic operations..(I implemented a kind of linked lists for linking the 1d arrays together...but the O(n) should not be a problem because the problem typically requires fetching only the data immediately next to the current item..)
    But the problem seems to be in the display...I'm having a bad experience ..trying to line out the output in the terminal..So any idea about implementing a graphical frontend (I'm thinking of learning a bit of QT) would be gold...

    he might want to move to Windows?
    Me?...nope.. *nix all the way...
    Last edited by manasij7479; 05-13-2011 at 12:20 PM.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to allocate huge array
    By Schumy in forum C Programming
    Replies: 5
    Last Post: 06-21-2006, 09:31 AM
  2. How do I make a *HUGE* array in C++?
    By rooster in forum C++ Programming
    Replies: 10
    Last Post: 02-27-2006, 07:05 PM
  3. Replies: 4
    Last Post: 04-02-2004, 06:30 PM
  4. Huge array
    By Shadow12345 in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2002, 03:49 AM
  5. Using a huge 3D array
    By Gabu in forum C++ Programming
    Replies: 3
    Last Post: 07-20-2002, 09:38 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21