Jump to content
  • Advertisement
Sign in to follow this  
seventhirty

C++ std::bitset vs char arr[]

This topic is 3341 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all ! : ) I'm implementing a tetris clone using C++ with SDL. I'm trying to choose a suitable representation of the game board and the tetris bricks and I was wondering which one of the following is better: 1. std::bitset<16> for each brick(4x4) and std::bitset<200> (10x20) for the game board. example(brick): 0000 0111 0100 0000 I'm initializing the bricks from a long int ( 736 for the example above). It takes some time to see what long corresponds to each bitset and I was wondering, say in a real project, does this optimization deserves the time.. or is it an optimization at all, I mean, I suppose operations ( like subscripting) on a bitset should be faster than operations on an array. What is more, some of the functions will be a bit harder to write using bitset rather than an array 2. char arr[4][4] or bool arr[4][4] for each brick is the other way i can think of. I'm trying to make the game as good and polished as possible, as it will go in my portfolio later.. Another quick question ( about SDL): When I blit stuff on the main surface, which one is better: 1.To have only two SDL_Surface* - one for the main sufrace(which the player actually sees) and one to: - load bitmap on; - blit it on the main surface; - free it; or is it better to: 2.Have a separate SDL_Surface for each bitmap that I will blit on screen? help would be very, very appreciated :)

Share this post


Link to post
Share on other sites
Advertisement
Quote:
I mean, I suppose operations ( like subscripting) on a bitset should be faster than operations on an array.
Why do you think that?

In any case, for a project like Tetris, I don't think it'll matter from a performance or memory consumption standpoint what method you use. Therefore, I would use whatever method makes for the cleanest, clearest, and most easily maintainable code.

(For the board, a static 2-d array would probably suffice, although I'd probably create a wrapper of some sort, if only to provide bounds checking. Another alternative would be to use boost::multi_array.)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!