GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #11  
Old 12-Apr-2006, 10:00
QED's Avatar
QED QED is offline
Member
 
Join Date: Feb 2005
Location: Hudson Valley, NY
Posts: 231
QED is a jewel in the roughQED is a jewel in the roughQED is a jewel in the rough

Re: Decks and Dice


Of course, the code I posted above will require that the compiler emit separate code for each N that you use in your program, rather than in the non-template version that uses a member variable for sides. Since the typical game will not have more than about a half-dozen different N's, this is not likely to be a concern.

With a simple program that does nothing but instantiate an instance of Dice for N=4,6,8,10,12,20, and call each member function once, I measured the code bloat as shown below (g++ 4.0).
Without compiler optimization (other than default):
Code:
-rwxr-xr-x 1 matthew matthew 7228 2006-04-12 10:41 testdice_mainonly -rwxr-xr-x 1 matthew matthew 8436 2006-04-12 10:55 testdice_notemplate -rwxr-xr-x 1 matthew matthew 10926 2006-04-12 10:55 testdice_template
With -O2 compiler optimizations:
Code:
-rwxr-xr-x 1 matthew matthew 7212 2006-04-12 10:41 testdice_mainonly -rwxr-xr-x 1 matthew matthew 8079 2006-04-12 10:55 testdice_notemplate -rwxr-xr-x 1 matthew matthew 9245 2006-04-12 10:55 testdice_template

Matthew

P.S. I forgot to mention something again. I did not use the RNG class, but simply called the rand() function for my test. It is just meant to give a rough idea anyhow.
__________________
I was born not knowing and have only had a little time to change that here and there. -- Richard P. Feynman

Boris Podolsky: James! How's the rat business?
James Moreland: Well, actually it's mostly students I'm experimenting on now.
Kurt Gödel: My God, the mazes must be enormous.
  #12  
Old 12-Apr-2006, 20:37
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough

Re: Decks and Dice


Thanks QED. I'm out of town working until this weekend but with davis' and your suggestions I am looking forward to playing with this when I get home. Your tips jive with the lines I had been thinking along.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #13  
Old 19-May-2006, 10:43
davis
 
Posts: n/a

Re: Decks and Dice


Quote:
Originally Posted by QED
CPP / C++ / C Code:
typedef Dice<4> Dice4;
typedef Dice<6> Dice6;
typedef Dice<8> Dice8;
typedef Dice<10> Dice10;
typedef Dice<12> Dice12;
typedef Dice<20> Dice20;

We both need to modify our code such that Dice<0> isn't allowed...

Of course, Dice<1> is of little use too, huh?


:davis:
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:41.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.