hello,
firstly sorry for the double post yesterday I had problems accessing the site. ok well i couldnt use lefence as my compiler claimed /usr/bin/ld: cannot find -lefence. Anyway I downloaded something called Valgrind and run my program through that. I must admit the results were a little grim and some of the problems I have no idea how to fix such as this :
Code:
==5492== Conditional jump or move depends on uninitialised value(s)
==5492== at 0x401868C1: vgAllRoadsLeadToRome_select (vg_intercept.c:702)
==5492== by 0x4018696E: __select (vg_intercept.c:722)
Its reffering to my select function which is just simply : select(CurrentFDMax+1,&read_fds,NULL, NULL, &tv); so not a clue how to fix that one. This is another error :
Code:
==5492== Syscall param write(buf) contains uninitialised or unaddressable byte(s)
==5492== Address 0x4167C9BC is 72 bytes inside a block of size 8192 alloc'd
although all the related files are in reference to my mysql.so files, so not sure if its a bug in them or in my code.
Anyway it did show me where I was going wrong with my linked lists and event checking function..
Basically i was doing this : (cut down)
Code:
void CheckEvents(struct node* head, int mud_counter) {
struct node* current = head;
while(current != NULL) {
if(current->ToOccur == mud_counter) {
switch(current->EventType)
{
case 1:
DoSomething();
break;
case 2:
DoSomethingElse();
DeleteTheEvent(current);
break;
case 3:
DoSomethingElse();
break;
}
}
current = current->next;
}
}
Where I was going wrong was if I found a event which needed deletion I was sending it to my delete function to be removed but afterwards still trying to do : current = current->next; Anyway Valgrind pointed out this was wrong. Do you think that could have been the cause of the random crashes aswell ? Anyhow I was trying to fgure out how I could get around it and came up with this :
Code:
void CheckEvents(struct node* head, int mud_counter) {
struct node* current = head;
struct node* next; // < using this as my next reference
while(current != NULL) {
if(current->ToOccur == mud_counter) {
switch(current->EventType)
{
case 1:
next = current->next;
DoSomething();
break;
case 2:
DoSomethingElse();
next = current->next;
DeleteTheEvent(current);
break;
case 3:
next = current->next;
DoSomethingElse();
break;
}
}
current = next;
}
}
Which i thought would work as Ill aways have my pointer to the next node and it works in that Valgrind doesnt complain about what im doing anymore but it seems to be doing an enormous amount of work as a ps -aux shows it to be using 20Megs of RSS when its running. Its also very very slow, so no doubt im either running a partial endless loop or just continuously expanding some memory somewhere. Could someone point out where im going wrong please or what I need to read up about to get my problem fixed. I think its this part : current = next; Ive tried fiddling around with it but cant seem to get it to run normally.
*EDIT * ok ive figured out that adding a default in the case statement stops if from going to real high RSS but now the main combat loop is going about a second slower than it was before I changed to using the next variable...
Anyway any help you may have will be greatly appreciated.
Thanks,
mrpickle.