Say have I have a global variable which is a C++ class object. What's the easiest way to ensure all the object's members (data and methods) get assigned to a named memory section (so I can easily place it, i.e., on-chip or off-chip)? I want to avoid littering the code with scores of #pragma's as that is going to make the class definition very unreadable and hard to follow.
Doing it all with a set of elaborate rules in my linker command file is fine, and, I think, that will be easy for the class methods (since they are defined in a specific .obj file), but I am unsure how to handle the member variables since are only defined in the header file and are not allocated until runtime by whatever module creates the object. (Actually, that would be true for methods, too, if the method is defined in the header file, right?)
Small Example (skipping standard coding practices):
cMyClass.h
class cMyClass
{
int m_Var1;
int m_Var2;
public:
int m_Var3;
public:
cMyClass();
~cMyClass(){}
int Method1();
int Method2(){return(m_Var1 + m_Var2);}
};
cMyClass.cpp
#include “cMyClass.h”
cMyClass::cMyClass()
{
m_Var1 = m_Var2 = m_Var3 = 0;
}
int cMyClass::Method1()
{
return m_Var3;
}
SomeFile.cpp
#include <stdio.h>
#include “cMyClass.h”
cMyClass AClassObj;
int main()
{
printf( “m_Var3 = %d\n”, AClassObj.Method1() );
return 0;
}
Now if I want to place the entire "AClassObj" object in my DDR2 memory section, how would I do that?