![]() |
Any of you string/pointer/memory guru's out there who can help me?
Well, i got my chat system work basicly. THanks to you guys i got the identification of a character working and for a moment i thought it was done. Until i began cleaning code and i saw there where tons of shit in it. So as a good boy i rewritten some tiny pieces in a more neat way and in point of few i did not fix or break a thing. It should simply work. Let me explain how the 'chat engine' works, its simple:
the ChatEngine class loads an ini file which consists of 'reply blocks'. Each reply block contains at max 10 words it should identify from a sentence typed by any user. When the reply block matches with most words, the corresponding 'reply sentences' given should be used to give a more sensable reply. I do not expect miracles, i do not expect super smart talks. But i dont want dumbshit things like "hehe, i killed you %n", etc. My crucial problem: When i type a sentence, it crashes. Not 100% of the time immidiatly, but mostly after the 2nd sentence i type, it does crash. It crashes randomly which makes it harder for me to track down the bug(s). I marked 2 spots where it crashes already. It also crashes randomly in some adress of HL.EXE. If you have any comments on how things should really be changed, you are free to mention. Although i am just looking for a bug, i find it hard to write good code with 'pointers' and such. I always mess up, and i never know why. I had a book which helped me mostly, but i lost it, darn. The chatengine.h contents: Code:
// Chatting Engine Code:
/** bot_client.cpp Code:
void BotClient_CS_SayText(void *p, int bot_index) There is another function that is important, its UTIL_SayTextBot(), its partial code from Podbots saytext. i figured that when i use this code the bots DO NOT recieve a SayText and they CANNOT intercept it via the above function. So i had to use the ChatEngine.set_sentence() to make it work. i really do not like that. It will make it harder for humans to interact with bots, it would be a real bot chat i'm afraid. Anyway: Code:
// POD SAYING: Thanks in advance for your help! EDIT: One question what is the difference between: Code:
char achar[80]; Code:
char achar[80]; |
Re: Any of you string/pointer/memory guru's out there who can help me?
Quote:
First off, the first one char achar[80]; achar[80] = 0; will produce an access violation error. You declare an array of characters, 80 characters wide. Then you tell it to put the 81th character to zero. I mean, Stefan, get more sleep, I *mean it* :D The second one char achar[80]; for (int i = 0; i < 80; i++) achar[i] = 0; will take each element of this array successively, starting from element #0 (first element) up to element #79 (80th element, i.e. the size of your array), and reset it to zero. ALL your character array will be reset to zero. What are you up to ?? *edit* OMG, I've just taken a deeper look in the code you posted, it's terrible!! 8o 8o 8o Do you know how many times you are writing beyond the limit of your arrays ??? And you wonder why your bot crashes randomly ?? omfg, if the hwole RealBot is written this way, then it's driven by MAGIC ! Fix that or do something but get this out of my sight quick !! :D *edit 2* OK, since I'm a good boy (well, I think...) I'm gonna give you a hint dude. To clear out an array without wasting time doing a test for each character, use memset(). char achar[80]; memset (achar, 0, sizeof (achar)); And your whole array is reset to zero, completely, it takes a millionth second. |
Re: Any of you string/pointer/memory guru's out there who can help me?
do you think everybody reads all this code ?
well, some functions which should be used and might be helpful. if you wanna get practice in coding such stuff nothing is against implementing it yourself, but 'inlining' it all the time looks a bit bad :
|
Re: Any of you string/pointer/memory guru's out there who can help me?
lol @ pmb:
First of all, my clearing was always done via those 'for' loops. But they are to long. And since i found in some other bots source that he did: achar[80]=0; i thought, heck, it probably means 'clear TILL' 80. Although i also was not 100% sure. Anyway. Since i read your post i bet i must be doing something terrible there. so i'll get on with that. I do not expect anyone to read my entire code, it mostly is an accumilating problem. Like pmb said, i did it multiple times wrong, it adds up wrong, it fucks up memory. Btw, i got some sleep now, around 3 hours;) |
Re: Any of you string/pointer/memory guru's out there who can help me?
thanks guys. I have rechecked my entire code, fixing up any bad allocaiton/initialization stuff. I also replaced some 'sprintf' thingies with strcpy.
AND IT WORKS NOW!!! yeeeeeehaw. Man, i am going to play around with this chat database and show off later. I am also gonna build in a 'thanks to' system that prints off a message (yes, this time memset cleared and not on 81 PMB :P ) once in a while. Oh,they also talk about BU, thats okay right? :D |
Re: Any of you string/pointer/memory guru's out there who can help me?
Quote:
btw why do you want to clear a string with memset? Just setting the first element to 0 is enough for an 'empty' string |
Re: Any of you string/pointer/memory guru's out there who can help me?
didn't you know that stefan is all the time running from his evil counterpart, a red clothed communist spy, sucking out all information he gets ? Therefore stefan has to erase all obsolete information when he doesnt need it any more.
@stefan : maybe you also just browse a bit in the MSDN - you can browse it on microsoft.com, somewhere. but the functions above are sufficient for some time now I guess |
Re: Any of you string/pointer/memory guru's out there who can help me?
@Asp: 'got something against commies, comrade ? :D
|
Re: Any of you string/pointer/memory guru's out there who can help me?
lol. I just have the habbit to clear out everything, so i am 100% sure the variable is clean and i dont screw up. I did screw up,but don't mention that.
For your pleassure. I ran my first test with a bigger database of words and such. Its not amazing, its not revolutionary, but its fun :) |
Re: Any of you string/pointer/memory guru's out there who can help me?
whoei, that looks nice8) .
can't wait to see it in live action. nice work :) btw. can we add more line costumely, and can we turn it off? |
Re: Any of you string/pointer/memory guru's out there who can help me?
Are all you guys masochists or something? Why subject yourself to the horrible pain of zero based character array manipulation when you could be using the standard C++ string class?
|
Re: Any of you string/pointer/memory guru's out there who can help me?
I dunno later on I want to but I think I'm to lazy to learn to use them and since I already use C strings... But I read some stuff about it and indeed its way simpeler. Especially I like the way you can use operators like == and += normaly. O well some day....
|
Re: Any of you string/pointer/memory guru's out there who can help me?
Rick, there's not much to learn about the string class really. The on going productivity loss futzing around with c strings will never end, so investing a couple hours into learning how to use the string class is well worth it.
http://www.msoe.edu/eecs/ce/courseinfo/stl/string.htm |
Re: Any of you string/pointer/memory guru's out there who can help me?
I'm still gonna stick to the character arrays, in spite of all this... yes.
I like to know where every single byte of memory goes to :) That's not a drawback for me because my code is usually rather ANSI C than C++. |
Re: Any of you string/pointer/memory guru's out there who can help me?
Quote:
|
Re: Any of you string/pointer/memory guru's out there who can help me?
"You could always write your own string class"
:D Exactly :D |
Re: Any of you string/pointer/memory guru's out there who can help me?
Quote:
|
Re: Any of you string/pointer/memory guru's out there who can help me?
Quote:
|
Re: Any of you string/pointer/memory guru's out there who can help me?
beware dude, just publish the Parabot sources and Stefan will hunt down every single bug to nag you with it! ;)
|
All times are GMT +2. The time now is 03:11. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.