Go Back   Computer Forums > Welcome To Computer Forums .org > Social Lounge | Off Topic
Click Here to Login
Join Computer forums Today


Closed Thread
 
Thread Tools Search this Thread Display Modes
 
Old 04-09-2008, 08:55 AM   #1
BSOD
 
Join Date: Apr 2008
Posts: 4
Cool Problems with a for loop

I am writting a rather complicated little node based tree and trying to iterate over the full and untouched set of n before the dijkstra implementation - seen here in pseudo code form : http://en.wikipedia.org/wiki/Dijkstra's_algorithm#Algorithm can complete full running.

Anyway - the current code I have is as follows:

for (loop=0; loop<NLOOP; loop++)
{
for (pass=0; pass<NPASS; pass++)
{
for (subpass=0; subpass<SUBP; subpass++)
{
for (i=0; i<MAXP; i++)
{
int rno = rand();
if (rno & 8)
{
if (pointers[i])
{
if (!(rno & realloc_mask))
{
r = rsize();
curmax -= size[i];
curmax += r;
pointers[i] = realloc(pointers[i], rsize());
size[i] = r;
if (absmax < curmax) absmax = curmax;
}
else
{
curmax -= size[i];
free(pointers[i]);
pointers[i] = 0;
}
}
else
{
r = rsize();
curmax += r;
pointers[i] = malloc(r);
size[i] = r;
if (absmax < curmax) absmax = curmax;
}
}
}
}
}

There is something odd about the curmax variable on the 76th and 95 iteration where it infact equals !=0.

Any ideas - im desperate.

Rolf
__________________

pugboy3 is offline  
Old 04-09-2008, 09:05 AM   #2
BSOD
 
Join Date: Apr 2008
Posts: 3
Default Re: Problems with a for loop

Good day to you Sir,

I observe that your code is indeed somewhat flawed in numerous occurring places. Please check your indentation, and recompile. This fixes numerous bugs and errors for me even including that somewhat elusive error of the most awful buffer overrun.

Also allocating memory in C is a sure fire Savoy Grill recipe for disaster. One must consider not just the implications of the memory allocation, but remember this: You must free not just the memory, but the whole object.

I hope my assistance is valued,

A Former Prime Minister.
__________________

LADY THATCHER is offline  
Old 04-09-2008, 09:07 AM   #3
BSOD
 
Join Date: Apr 2008
Posts: 4
Default Re: Problems with a for loop

christ - ofcourse the whole object hence the invalid memory seeks to 0x45baaaaaa

Dam.

Thatcher - thanks so much, you are a downright legend.

One other problem I am experiancing is that the line:

for (subpass=0; subpass<SUBP; subpass++)

seems to never get executed. Somebody told me to attempt a pin dial drop on it - but this got washed under the execution path of the seventeen void statements above it.

Confused :S
pugboy3 is offline  
Old 04-09-2008, 12:28 PM   #4
Site Team
 
celegorm's Avatar
 
Join Date: Sep 2006
Posts: 10,713
Send a message via AIM to celegorm
Default Re: Problems with a for loop

One member, two accounts. Banned and closed.
__________________
"as a fanboy i refuse to admit it and will pull countless things out of my butt to disprove it"

Team Thelegorm! Total Kills: 21 (i iz in uor profile, editsing your sigz)
celegorm is offline  
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 01:33 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0