[gameprogrammer] Re: dynamic array allocation in a class?
- From: "Justin Coleman" <JMCOLE@xxxxxxxxx>
- To: <gameprogrammer@xxxxxxxxxxxxx>
- Date: Fri, 11 Jun 2004 10:59:52 -0400
>>> daveslutzkin@xxxxxxxxxxx 6/10/2004 7:56:11 PM >>>
>...If they were written by the book in
>C++, I expect they'd be in their own source file, with accessor
functions
>and constructors... That would be overkill, but I'd expect to see it
in
>a dogmatic C++ style interpretation.
I'm not a big fan of "dogmatic C++". I put the stuff that goes
together, together... and I use only as many files as are necessary. I
see no need to make custom accessors, etc etc unless they're actually
needed. I'm trying to just use the parts of C++ that make things easier
for me :)
>OK. In general, I find vectors clearer and less error-prone,
because:
>- they take care of allocation and deallocation (rather than making
you
>do a new and delete, and forget the delete)
>- you've always got the size accessible (with dynamically allocated
>arrays, you almost always have to store the size separately anyway),
and
>- you get some (limited) bounds checking (if you use get instead of
>operator[])
All well and good, however I can't imagine vectors being nearly as fast
as an array of structs, primarily from the fact that there's a
new/malloc done for every new element added. For the game I'm working
on, I plan to have vast numbers of star systems, with the attendant vast
numbers of spaceships. (And yes, I do only plan to have one sphere
object with geometry data :) Saving and loading need to be as quick as
possible, so I'm concerned about vectors for this. I'll test them both
though, just in case.
>You don't need 'typedef struct...' in C++ code ... The name of a
structure is
>automatically a type,
Duly noted, that does make things easier to read. I was just using the
typedef so I could use those structures elsewhere in my code (outside
the class), didn't realize it was unnecessary.
>In C++ and OOP, you generally wouldn't have data public.
This is for debugging purposes, and will be changed eventually. IMO it
would be a waste of time writing accessor functions for each variable in
a class simply so I could dump the value to cout. (I hate the .net
debugger, and cout is mapped to a file for my perusal later).
>Inside the class declaration, you don't need the class name as a
prefix
I'm anticipating having very long class definitions, with lots of
members. The class name helps me keep track of which one I'm looking at,
since the VS.net code window isn't very large.
> it's often more enjoyable to
> reimplement yourself, as you learn a lot more that way. So just
keep
> that in mind, anyway.
Amen! And that's why I'm going to all this trouble rather than just
licensing some library :)
>Hope that helps,
>
>Dave.
It does, thanks a ton. This list is a great resource!
-Justin
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: dynamic array allocation in a class?
- From: Dave Slutzkin
Other related posts:
- » [gameprogrammer] dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- » [gameprogrammer] Re: dynamic array allocation in a class?
- [gameprogrammer] Re: dynamic array allocation in a class?
- From: Dave Slutzkin