C
codewarr2000
Having problem with retrieving a class instance item from a Vector.
This is the result of the code below.
Also a weird note: If I dont declare as:
TYPE_VECTOR_BANKED_MEMORY_DATA
bankedDataMemoryLayout(NUMBER_BANKS);
but an empty vector
TYPE_VECTOR_BANKED_MEMORY_DATA bankedDataMemoryLayout;
The program crashes on the 3rd insertion???
Additionally in the printout routine I am having a problem with using
an iterator. Can I not use an iterator?
PRIMING THE VECTOR:
STARTING ADDRESS: [c000] ENDING ADDRESS: [feff]
STARTING ADDRESS: [380000] ENDING ADDRESS: [3cbfff]
STARTING ADDRESS: [3d0000] ENDING ADDRESS: [3dbfff]
STARTING ADDRESS: [3e0000] ENDING ADDRESS: [3ebfff]
The size is: 8
Dumping contents of banks
STARTING ADDRESS: [0] ENDING ADDRESS: [0]
STARTING ADDRESS: [fdfdfdfd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
THE CODE PROGRAM:
---------------------------------------
class bankedMemoryDataClass
{
public:
//bankedMemoryDataClass(){}
bankedMemoryDataClass():
bankStartingMemoryAddress(0),
bankEndingMemoryAddress(0){};
~bankedMemoryDataClass(){}
unsigned long int getBankStartingMemoryAddress() const { return
bankStartingMemoryAddress;}
unsigned long int getBankEndingMemoryAddress() const {return
bankEndingMemoryAddress;}
void setBankStartingMemoryAddress(unsigned long int start){
bankStartingMemoryAddress = start;}
void setBankEndingMemoryAddress(unsigned long int end){
bankEndingMemoryAddress = end;}
private:
unsigned long int bankStartingMemoryAddress;
unsigned long int bankEndingMemoryAddress;
};
const int NUMBER_BANKS = 4;
typedef vector<bankedMemoryDataClass> TYPE_VECTOR_BANKED_MEMORY_DATA;
TYPE_VECTOR_BANKED_MEMORY_DATA bankedDataMemoryLayout(NUMBER_BANKS);
TYPE_VECTOR_BANKED_MEMORY_DATA::iterator
iteratorBankedDataMemoryLayout;
TYPE_VECTOR_BANKED_MEMORY_DATA::reference
referenceToBankData(TYPE_VECTOR_BANKED_MEMORY_DATA &);
//---------------------------------------------------------------------------
void initializeBankedMemoryLayout(void){
bankedMemoryDataClass tempObject;
iteratorBankedDataMemoryLayout = bankedDataMemoryLayout.begin();
cout.setf(std::ios::showbase);
tempObject.setBankStartingMemoryAddress(0xC000);
tempObject.setBankEndingMemoryAddress( 0xFEFF);
cout << "STARTING ADDRESS: [" << hex <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" << hex <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
bankedDataMemoryLayout.insert(iteratorBankedDataMemoryLayout,tempObject);
iteratorBankedDataMemoryLayout++;
tempObject.setBankStartingMemoryAddress(0x380000);
tempObject.setBankEndingMemoryAddress( 0x3CBFFF);
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
bankedDataMemoryLayout.insert(iteratorBankedDataMemoryLayout,tempObject);
iteratorBankedDataMemoryLayout++;
tempObject.setBankStartingMemoryAddress(0x3D0000);
tempObject.setBankEndingMemoryAddress( 0x3DBFFF);
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
bankedDataMemoryLayout.insert(iteratorBankedDataMemoryLayout,tempObject);
iteratorBankedDataMemoryLayout++;
tempObject.setBankStartingMemoryAddress(0x3E0000);
tempObject.setBankEndingMemoryAddress( 0x3EBFFF);
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
bankedDataMemoryLayout.insert(iteratorBankedDataMemoryLayout,tempObject);
//cout.setf(std::ios::noshowbase);
cout << "The size is: " << bankedDataMemoryLayout.size() << endl;
}
void printOutBankedMemoryLayout(void){
bankedMemoryDataClass tempObject;
cout << endl << "Dumping contents of banks" << endl << endl;
for (int i=0; i<8; i++)
{
tempObject = bankedDataMemoryLayout[i *
sizeof(bankedMemoryDataClass)];
//cout << "bank (" << *iteratorBankedDataMemoryLayout << ") ";
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
}
/*
for (iteratorBankedDataMemoryLayout = bankedDataMemoryLayout.begin();
iteratorBankedDataMemoryLayout != bankedDataMemoryLayout.end();
iteratorBankedDataMemoryLayout++){
tempObject =
bankedDataMemoryLayout.at((int)*iteratorBankedDataMemoryLayout);
cout << "bank (" << *iteratorBankedDataMemoryLayout << ") ";
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress << "]" << endl;
}
*/
}
int main(int argc, char* argv[])
{
int index;
initializeBankedMemoryLayout();
printOutBankedMemoryLayout();
return 1;
}
This is the result of the code below.
Also a weird note: If I dont declare as:
TYPE_VECTOR_BANKED_MEMORY_DATA
bankedDataMemoryLayout(NUMBER_BANKS);
but an empty vector
TYPE_VECTOR_BANKED_MEMORY_DATA bankedDataMemoryLayout;
The program crashes on the 3rd insertion???
Additionally in the printout routine I am having a problem with using
an iterator. Can I not use an iterator?
PRIMING THE VECTOR:
STARTING ADDRESS: [c000] ENDING ADDRESS: [feff]
STARTING ADDRESS: [380000] ENDING ADDRESS: [3cbfff]
STARTING ADDRESS: [3d0000] ENDING ADDRESS: [3dbfff]
STARTING ADDRESS: [3e0000] ENDING ADDRESS: [3ebfff]
The size is: 8
Dumping contents of banks
STARTING ADDRESS: [0] ENDING ADDRESS: [0]
STARTING ADDRESS: [fdfdfdfd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
STARTING ADDRESS: [dddddddd] ENDING ADDRESS: [dddddddd]
THE CODE PROGRAM:
---------------------------------------
class bankedMemoryDataClass
{
public:
//bankedMemoryDataClass(){}
bankedMemoryDataClass():
bankStartingMemoryAddress(0),
bankEndingMemoryAddress(0){};
~bankedMemoryDataClass(){}
unsigned long int getBankStartingMemoryAddress() const { return
bankStartingMemoryAddress;}
unsigned long int getBankEndingMemoryAddress() const {return
bankEndingMemoryAddress;}
void setBankStartingMemoryAddress(unsigned long int start){
bankStartingMemoryAddress = start;}
void setBankEndingMemoryAddress(unsigned long int end){
bankEndingMemoryAddress = end;}
private:
unsigned long int bankStartingMemoryAddress;
unsigned long int bankEndingMemoryAddress;
};
const int NUMBER_BANKS = 4;
typedef vector<bankedMemoryDataClass> TYPE_VECTOR_BANKED_MEMORY_DATA;
TYPE_VECTOR_BANKED_MEMORY_DATA bankedDataMemoryLayout(NUMBER_BANKS);
TYPE_VECTOR_BANKED_MEMORY_DATA::iterator
iteratorBankedDataMemoryLayout;
TYPE_VECTOR_BANKED_MEMORY_DATA::reference
referenceToBankData(TYPE_VECTOR_BANKED_MEMORY_DATA &);
//---------------------------------------------------------------------------
void initializeBankedMemoryLayout(void){
bankedMemoryDataClass tempObject;
iteratorBankedDataMemoryLayout = bankedDataMemoryLayout.begin();
cout.setf(std::ios::showbase);
tempObject.setBankStartingMemoryAddress(0xC000);
tempObject.setBankEndingMemoryAddress( 0xFEFF);
cout << "STARTING ADDRESS: [" << hex <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" << hex <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
bankedDataMemoryLayout.insert(iteratorBankedDataMemoryLayout,tempObject);
iteratorBankedDataMemoryLayout++;
tempObject.setBankStartingMemoryAddress(0x380000);
tempObject.setBankEndingMemoryAddress( 0x3CBFFF);
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
bankedDataMemoryLayout.insert(iteratorBankedDataMemoryLayout,tempObject);
iteratorBankedDataMemoryLayout++;
tempObject.setBankStartingMemoryAddress(0x3D0000);
tempObject.setBankEndingMemoryAddress( 0x3DBFFF);
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
bankedDataMemoryLayout.insert(iteratorBankedDataMemoryLayout,tempObject);
iteratorBankedDataMemoryLayout++;
tempObject.setBankStartingMemoryAddress(0x3E0000);
tempObject.setBankEndingMemoryAddress( 0x3EBFFF);
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
bankedDataMemoryLayout.insert(iteratorBankedDataMemoryLayout,tempObject);
//cout.setf(std::ios::noshowbase);
cout << "The size is: " << bankedDataMemoryLayout.size() << endl;
}
void printOutBankedMemoryLayout(void){
bankedMemoryDataClass tempObject;
cout << endl << "Dumping contents of banks" << endl << endl;
for (int i=0; i<8; i++)
{
tempObject = bankedDataMemoryLayout[i *
sizeof(bankedMemoryDataClass)];
//cout << "bank (" << *iteratorBankedDataMemoryLayout << ") ";
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress() << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress() << "]" << endl;
}
/*
for (iteratorBankedDataMemoryLayout = bankedDataMemoryLayout.begin();
iteratorBankedDataMemoryLayout != bankedDataMemoryLayout.end();
iteratorBankedDataMemoryLayout++){
tempObject =
bankedDataMemoryLayout.at((int)*iteratorBankedDataMemoryLayout);
cout << "bank (" << *iteratorBankedDataMemoryLayout << ") ";
cout << "STARTING ADDRESS: [" <<
tempObject.getBankStartingMemoryAddress << "] ";
cout << "ENDING ADDRESS: [" <<
tempObject.getBankEndingMemoryAddress << "]" << endl;
}
*/
}
int main(int argc, char* argv[])
{
int index;
initializeBankedMemoryLayout();
printOutBankedMemoryLayout();
return 1;
}