I've just noticed that when a class is created it only allocates the amount of memory required to hold the class properties. Does this mean I could manually make a 'new' class by having a structure with the same properties as a class, set it's values and then cast a pointer to the class to that bit of memory?
At the moment my list class uses HeapAlloc and allocs in variable size chunks as required, but I am wondering if I can also allocate a block of actual classes in the same way because at the moment I have typically a couple of thousand "new" calls for a game, but with the lists those items are stored in being preallocated.
- Code:
class Test
{
private:
int Priv1;
public:
int Prop1, Prop2, Prop3;
}
struct
{
int Priv1, Prop1, Prop2, Prop3;
} TestStruct;
TestStruct arrayOfClasses[20];
At the moment my list class uses HeapAlloc and allocs in variable size chunks as required, but I am wondering if I can also allocate a block of actual classes in the same way because at the moment I have typically a couple of thousand "new" calls for a game, but with the lists those items are stored in being preallocated.