|
2 registered members (OptimusPrime, AndrewAMD),
14,580
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Script Crash loves me :(
[Re: WretchedSid]
#411759
11/19/12 15:34
11/19/12 15:34
|
Joined: Jan 2004
Posts: 3,023 The Netherlands
Helghast
Expert
|
Expert
Joined: Jan 2004
Posts: 3,023
The Netherlands
|
...but the structs content remain uninitialized and might very well be something else than NULL. How should that happen? By sys_malloc() not zeroing the allocated memory? malloc doesnt, sys_malloc does 
|
|
|
Re: Script Crash loves me :(
[Re: Uhrwerk]
#411844
11/20/12 12:21
11/20/12 12:21
|
Joined: Nov 2011
Posts: 139 India
Yashas
OP
Member
|
OP
Member
Joined: Nov 2011
Posts: 139
India
|
if(Temp->next)
{
Temp = Temp->next;
}
It's exactly same as the code that I have given at the start of this post. Just found wheres the crash, I want to fix it not new ways 
Last edited by Yashas; 11/20/12 12:25. Reason: Forgot to close code tag :D
|
|
|
Re: Script Crash loves me :(
[Re: Uhrwerk]
#411928
11/21/12 11:08
11/21/12 11:08
|
Joined: Nov 2011
Posts: 139 India
Yashas
OP
Member
|
OP
Member
Joined: Nov 2011
Posts: 139
India
|
Can anyone give me some code for Unregistering a element from the linked list given JustSid. This was what I had done for my linked list.Now I am following what JustSid code does 
int UnregisterApplet(Applet * applet)
{
if(!applet) { return error("RegisterApplet:Invalid Applet"); }
AppletList * Temp = Applets;
while(1)
{
if(!Temp->next)
{
return error("UnregisterApplet:Could not find the spcified Applet");
break;
}
if(Temp->applet == applet)
{
AppletList * Temp2 = Temp->previous;
Temp2->next = Temp->next;
Temp2 = Temp->next;
Temp2->previous = Temp->previous;
return 0;
}
else
{
Temp = Temp->next;
}
}
}
Thanks
|
|
|
Re: Script Crash loves me :(
[Re: Yashas]
#411930
11/21/12 11:31
11/21/12 11:31
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
There you go:
void UnregisterApplet(Applet *applet)
{
if(applet->prev)
applet->prev->next = applet->next;
if(applet->next)
applet->next->prev = applet->prev;
if(applet == listHead)
listHead = applet->next;
if(applet == listTail)
listTail = applet->prev;
}
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Script Crash loves me :(
[Re: WretchedSid]
#411933
11/21/12 11:56
11/21/12 11:56
|
Joined: Nov 2011
Posts: 139 India
Yashas
OP
Member
|
OP
Member
Joined: Nov 2011
Posts: 139
India
|
How do I get number of elements??(I hav planned to keep moving to next pointer till a get a NULL) Any other efficient way??
And the listHead is the first element of the linked list right?? and listTail,the last??
Thanks
Last edited by Yashas; 11/21/12 12:01. Reason: Made it clear
|
|
|
Re: Script Crash loves me :(
[Re: Yashas]
#411941
11/21/12 12:54
11/21/12 12:54
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
No, that is the most efficient way to calculate it. The only alternative is caching the value, i.e. incrementing a var every time something is added to the list and decrementing it whenever something gets removed.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Script Crash loves me :(
[Re: Uhrwerk]
#411943
11/21/12 13:16
11/21/12 13:16
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
The only alternative is caching the value Which might not be a bad idea after all. Generally speaking it's better to wrap the linked list into some kind of container which abstracts the process of adding and removing references to the list so you don't have to implement it over and over again every time you need a linked list (and the container can also keep track of the number of nodes). I have posted a fairly basic example of such a linked list here: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=408638#Post408638
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Script Crash loves me :(
[Re: Yashas]
#411969
11/21/12 15:37
11/21/12 15:37
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Time to search elements in a linked list is linear. You cannot change that until you back the linked list by another data structure or use a completely different one, e.g. a hashmap.
You shouldn't bother about this anyways, as long as you don't have a sever speed problem.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
|
|
|