Original Post
Hi there! I just checked out virtual functions, and have a question for ya´ll. :) Is the memory allocated when "new" is called...? simply; is the extra memory needed for the path allocated when a PlayerCar is "born" (using new), or does the compiler see this and allocates all memory needed at bootup, i.e for ALL the baseclasses...? Would this virtual approach save memory if you had say, 10000 cars in which only 100 has pathfinding... compared to 10000 cars where all have pathfinding, except that only 100 use it.... It's really noobish, I know, but when you don't know - you don't know! The old way I did things was to have ONE class with all variables in it... but since I use the TaskManager to monitor the memory, I cant really see a large change in consumtion...
class baseobject
{
public:
vertex3f Pos;
int UniqueID,Type,Owner;
virtual void Draw() =0 ;
};
baseobject* Vehicle[MAX_NR_VEHICLES];
class StaticCar: public baseobject
{
public:
wheel *Wheel[4];
void Draw();
};
class PlayerCar : public baseobject
{
public:
wheel *Wheel[4];
vertex3f Path[MAX_NR_SEARCH_STEPS];
void Draw();
};