B
Bryan Parkoff
I have created three classes according to my own design. First class
is called CMain. It is the Top Class. Second class and third class are
called CMemory and CMPU. They are the sub-classes.
Two sub-classes have the relationship to communicate back and forth
through this pointer. The pointer is responsible inside Top class for
allocating and deallocating two sub-classes.
CMemory class is responsible to allocate and deallocate memory while
CMPU class does not. I tell the pointer to copy m_pMemoryRegister's
memory address from CMemory class to CMPU class. It is done once during
the initialization.
After the initialization is done, the functionality can perform all
the tasks inside CMPU class rather than depending on CMemory class so it
can gain a big impact of this performance.
I understand that some C programmers prefer to leave all variables
and functions in the global. In fact, it won't be efficiency because all
variables and functions have fixed memory that they are stored in data
segment. They can't perform the tasks into 80x86's L1 Cache.
It is best to store both variables and functions inside class because
they can be very efficiency. They are stored in stack segment. They can
be able to perform the tasks into 80x86's L1 Cache.
Please read my simple code below. Please state your opinion to see
if my programming code for class is a good design. I appreciate that you
can provide what you think is best.
class CMain
{
public:
CMain();
virtual ~CMain();
CMemory* Get_Memory();
CMPU* Get_MPU();
void Initialize(void);
void Terminate(void);
void Run(void);
private:
CMemory* m_pMemory;
CMPU6502* m_pMPU;
};
CMain::CMain()
{
m_pMemory = new CMemory(this);
m_pMPU = new CMPU(this);
}
CMain::~CMain()
{
delete m_pMemory;
delete m_pMPU;
}
CMemory* CMain::Get_Memory()
{
return m_pMemory;
}
CMPU* CMain::Get_MPU()
{
return m_pMPU;
}
void CMain::Initialize(void)
{
}
void CMain::Terminate(void)
{
}
void CMain::Run(void)
{
m_pMPU->Run();
}
class CMemory
{
public:
CMemory();
virtual ~CMemory();
CMemory(CMain* pMain);
void Initialize(void);
void Terminate(void);
void Run(void);
unsigned char Get_MemoryRegister(void);
private:
CMain* m_pMain;
unsigned char m_pMemoryRegister;
};
CMemory::CMemory()
{
Initialize();
}
CMemory::~CMemory()
{
Terminate();
}
CMemory::CMemory(CMain* pMain)
{
m_pMain = pMain;
Initialize();
}
void CMemory::Initialize(void)
{
m_pMemoryRegister = new unsigned char [0x10000];
memset(&m_pMemoryRegister[0], 0x00, 0x10000);
}
void CMemory::Terminate(void)
{
delete [] m_pMemoryRegister;
}
void CMemory::Run(void)
{
}
PU_BYTE CMemory::Get_MemoryRegister(void)
{
return m_pMemoryRegister;
}
class CMPU
{
public:
CMPU();
virtual ~CMPU();
CMPU(CMain* pMain);
void Initialize(void);
void Terminate(void);
void Run(void);
private:
CMain* m_pMain;
unsigned char m_pMemoryRegister;
};
CMPU::CMPU()
{
Initialize();
}
CMPU::~CMPU()
{
Terminate();
}
CMPU::CMPU(CMain* pMain)
{
m_pMain = pMain;
Initialize();
}
void CMPU::Initialize(void)
{
m_pMemoryRegister = m_pMain->Get_Memory()->Get_MemoryRegister();
}
void CMPU6502::Terminate(void)
{
}
void CMPU6502::Run(void)
{
}
int main(void)
{
CMain Main;
Main.Run();
return 0;
}
is called CMain. It is the Top Class. Second class and third class are
called CMemory and CMPU. They are the sub-classes.
Two sub-classes have the relationship to communicate back and forth
through this pointer. The pointer is responsible inside Top class for
allocating and deallocating two sub-classes.
CMemory class is responsible to allocate and deallocate memory while
CMPU class does not. I tell the pointer to copy m_pMemoryRegister's
memory address from CMemory class to CMPU class. It is done once during
the initialization.
After the initialization is done, the functionality can perform all
the tasks inside CMPU class rather than depending on CMemory class so it
can gain a big impact of this performance.
I understand that some C programmers prefer to leave all variables
and functions in the global. In fact, it won't be efficiency because all
variables and functions have fixed memory that they are stored in data
segment. They can't perform the tasks into 80x86's L1 Cache.
It is best to store both variables and functions inside class because
they can be very efficiency. They are stored in stack segment. They can
be able to perform the tasks into 80x86's L1 Cache.
Please read my simple code below. Please state your opinion to see
if my programming code for class is a good design. I appreciate that you
can provide what you think is best.
class CMain
{
public:
CMain();
virtual ~CMain();
CMemory* Get_Memory();
CMPU* Get_MPU();
void Initialize(void);
void Terminate(void);
void Run(void);
private:
CMemory* m_pMemory;
CMPU6502* m_pMPU;
};
CMain::CMain()
{
m_pMemory = new CMemory(this);
m_pMPU = new CMPU(this);
}
CMain::~CMain()
{
delete m_pMemory;
delete m_pMPU;
}
CMemory* CMain::Get_Memory()
{
return m_pMemory;
}
CMPU* CMain::Get_MPU()
{
return m_pMPU;
}
void CMain::Initialize(void)
{
}
void CMain::Terminate(void)
{
}
void CMain::Run(void)
{
m_pMPU->Run();
}
class CMemory
{
public:
CMemory();
virtual ~CMemory();
CMemory(CMain* pMain);
void Initialize(void);
void Terminate(void);
void Run(void);
unsigned char Get_MemoryRegister(void);
private:
CMain* m_pMain;
unsigned char m_pMemoryRegister;
};
CMemory::CMemory()
{
Initialize();
}
CMemory::~CMemory()
{
Terminate();
}
CMemory::CMemory(CMain* pMain)
{
m_pMain = pMain;
Initialize();
}
void CMemory::Initialize(void)
{
m_pMemoryRegister = new unsigned char [0x10000];
memset(&m_pMemoryRegister[0], 0x00, 0x10000);
}
void CMemory::Terminate(void)
{
delete [] m_pMemoryRegister;
}
void CMemory::Run(void)
{
}
PU_BYTE CMemory::Get_MemoryRegister(void)
{
return m_pMemoryRegister;
}
class CMPU
{
public:
CMPU();
virtual ~CMPU();
CMPU(CMain* pMain);
void Initialize(void);
void Terminate(void);
void Run(void);
private:
CMain* m_pMain;
unsigned char m_pMemoryRegister;
};
CMPU::CMPU()
{
Initialize();
}
CMPU::~CMPU()
{
Terminate();
}
CMPU::CMPU(CMain* pMain)
{
m_pMain = pMain;
Initialize();
}
void CMPU::Initialize(void)
{
m_pMemoryRegister = m_pMain->Get_Memory()->Get_MemoryRegister();
}
void CMPU6502::Terminate(void)
{
}
void CMPU6502::Run(void)
{
}
int main(void)
{
CMain Main;
Main.Run();
return 0;
}