Click here to Skip to main content
15,908,776 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhelp in erasing the part of string Pin
tasumisra14-Dec-08 21:14
tasumisra14-Dec-08 21:14 
AnswerRe: help in erasing the part of string Pin
Paresh Chitte14-Dec-08 21:21
Paresh Chitte14-Dec-08 21:21 
GeneralRe: help in erasing the part of string Pin
tasumisra14-Dec-08 21:28
tasumisra14-Dec-08 21:28 
AnswerRe: help in erasing the part of string Pin
Jijo.Raj14-Dec-08 21:48
Jijo.Raj14-Dec-08 21:48 
JokeRe: help in erasing the part of string Pin
CPallini15-Dec-08 2:02
mveCPallini15-Dec-08 2:02 
AnswerRe: help in erasing the part of string Pin
CPallini14-Dec-08 21:53
mveCPallini14-Dec-08 21:53 
GeneralRe: help in erasing the part of string Pin
tasumisra14-Dec-08 22:15
tasumisra14-Dec-08 22:15 
QuestionDangling pointers and incorrect data being written Pin
Mustafa Ismail Mustafa14-Dec-08 20:02
Mustafa Ismail Mustafa14-Dec-08 20:02 
when you have a method prototype as such:

<code>
void setCacheBlocks(vector<cacheblock> const &value);
</cacheblock></code>

and an implementation as such:

<code>
void Simulator::setCacheBlocks(vector<cacheblock> const & value)
{
m_CacheBlock = value;
}
</cacheblock></code>

And when you run the code, the size of items in the vector is correct, but the actual contents of each object contained by the vector magically disappears?

here's what's actually happening (keep in mind this is a mutation of several generations)

<code>

void Simulator::Simulate()
{
Splash();
getUserSettings();
cout.clear();
cout &lt;&lt; "Reading trace file..." &lt;&lt; endl;
GetData();
sleep(2);
cout &lt;&lt; "\nData read.\nStarting Simulation..." &lt;&lt; endl;
sleep(1);

// simulation start
//create the data blocks and the cache sets
//create the Cache Blocks
CreateCacheBlocks();
//create the Cache Sets
CreateCacheSets();
}

void Simulator::CreateCacheBlocks()
{
uint numBlocks = getSettings().getCacheSize()/getSettings().getBlocksSize();

uint maxOffset = getSettings().getOffsetParity();
uint bTag = getSettings().getTagParity();
uint bIndex = getSettings().getIndexParity();
bool isValid = false;
char* bData = new char[maxOffset - 1]; //just to make it 0 based
for(int i = 0; i &lt; maxOffset; i++)
{
bData[i] = NULL;
}

vector&lt;cacheblock&gt; v;

CacheBlock cb;
cb.Initialize(maxOffset,bTag,bIndex,isValid,bData);

cb.setSettings(m_Settings);
//initialize each cache block to an initial state
for(uint i = 0; i &lt; numBlocks; i++)
{
cb.setBlockNumber(i);
cb.setBlockAddress(cb.CalculateBlockAddress(i));
v.push_back(cb);
}
//TODO: fix this ASAP
//setCacheBlocks(v);
m_CacheBlock = v;
}

void Simulator::CreateCacheSets()
{
uint numBlocks = getSettings().getCacheSize()/getSettings().getBlocksSize();
uint numSets = numBlocks/getSettings().getCacheAssociativity();

uint numBlocksPerSet = numBlocks / numSets;


CacheSet cs;
cs.setSettings(getSettings());
vector<cacheset> v;

//create the correct number of sets and assign their set indexes
for(uint i = 0; i &lt; numSets; i++)
{
cs.setSetIndex(i);
v.push_back(cs);
}

int k = v.size();
CacheBlock cb;

//assign each cache block to its set
uint setIx = 0;
for(uint i = 0; i &lt; numBlocks; i++)
{

setIx = getCacheBlocks()[i].getBlockAddress() &lt;&lt; getSettings().getTagParity();
setIx &gt;&gt;= getSettings().getTagParity();
//cb = getCacheBlocks()[i];
cb = m_CacheBlock[i]; //this statement should be exactly like the preceding one in worth
v[setIx].getCacheBlocks().push_back(cb);
}

setCacheSet(v);
}

</cacheset></cacheblock></code>

If you look to the method Simulate, everything works fine, including CreateCacheBlocks(), but things go belly up in CreateCacheSets().

Yes, I know I shouldn't be using getXX()/setXX() but this is the second time I've had to deal with this Prof and he's old and really old school and doesn't want to get with the times of using overloaded methods.

Don't forget to vote if the response was helpful

Sig history

"dad" Ishmail-Samuel Mustafa

Unix is a Four Letter Word, and Vi is a Two Letter Abbreviation

"There is no wealth like knowledge, no poverty like ignorance" Ali Ibn Abi Talib
AnswerRe: Dangling pointers and incorrect data being written Pin
Cedric Moonen14-Dec-08 20:48
Cedric Moonen14-Dec-08 20:48 
GeneralRe: Dangling pointers and incorrect data being written Pin
Mustafa Ismail Mustafa14-Dec-08 21:11
Mustafa Ismail Mustafa14-Dec-08 21:11 
GeneralRe: Dangling pointers and incorrect data being written Pin
Stuart Dootson14-Dec-08 21:31
professionalStuart Dootson14-Dec-08 21:31 
GeneralRe: Dangling pointers and incorrect data being written Pin
Mustafa Ismail Mustafa14-Dec-08 21:42
Mustafa Ismail Mustafa14-Dec-08 21:42 
GeneralRe: Dangling pointers and incorrect data being written Pin
Stuart Dootson14-Dec-08 22:07
professionalStuart Dootson14-Dec-08 22:07 
GeneralRe: Dangling pointers and incorrect data being written Pin
Mustafa Ismail Mustafa15-Dec-08 1:43
Mustafa Ismail Mustafa15-Dec-08 1:43 
GeneralRe: Dangling pointers and incorrect data being written Pin
Stuart Dootson15-Dec-08 13:37
professionalStuart Dootson15-Dec-08 13:37 
GeneralRe: Dangling pointers and incorrect data being written Pin
Mustafa Ismail Mustafa16-Dec-08 18:21
Mustafa Ismail Mustafa16-Dec-08 18:21 
GeneralRe: Dangling pointers and incorrect data being written Pin
Stuart Dootson16-Dec-08 19:40
professionalStuart Dootson16-Dec-08 19:40 
GeneralRe: Dangling pointers and incorrect data being written Pin
Mustafa Ismail Mustafa16-Dec-08 19:50
Mustafa Ismail Mustafa16-Dec-08 19:50 
GeneralRe: Dangling pointers and incorrect data being written Pin
Stuart Dootson16-Dec-08 21:52
professionalStuart Dootson16-Dec-08 21:52 
GeneralRe: Dangling pointers and incorrect data being written Pin
Mustafa Ismail Mustafa16-Dec-08 23:50
Mustafa Ismail Mustafa16-Dec-08 23:50 
GeneralRe: Dangling pointers and incorrect data being written Pin
Stuart Dootson17-Dec-08 2:34
professionalStuart Dootson17-Dec-08 2:34 
GeneralRe: Dangling pointers and incorrect data being written Pin
Mustafa Ismail Mustafa17-Dec-08 4:47
Mustafa Ismail Mustafa17-Dec-08 4:47 
GeneralRe: Dangling pointers and incorrect data being written Pin
Stuart Dootson17-Dec-08 5:18
professionalStuart Dootson17-Dec-08 5:18 
GeneralRe: Dangling pointers and incorrect data being written [modified] Pin
Mustafa Ismail Mustafa17-Dec-08 5:52
Mustafa Ismail Mustafa17-Dec-08 5:52 
GeneralRe: Dangling pointers and incorrect data being written Pin
Stuart Dootson17-Dec-08 6:25
professionalStuart Dootson17-Dec-08 6:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.