Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Help with strings tier 2!

Author
Message
sovr
14
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 10th Aug 2014 20:13
Hello! I have been having a hard time trying to properly concat two strings (or char[]) into one string. here is my code so far:



The code can be confusing, but the only part I am having trouble is where I do:



I have tried to delete the DirStr with delete(DirStr) and delete[] (DirStr) and it runs into an exception. If I leave it alone and do not delete it, it freezes and crashes. I will try to figure out the exception, but I do need help! Thank you in advance!

website: http://worksimpleintelligen.wix.com/parkers-apps
facebook: https://www.facebook.com/ParkersApps
youtube: http://www.youtube.com/user/mrsovr
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 10th Aug 2014 21:38
Have you tried defining DirStr outside the Loop? Looks to me as though you are allocating a new string several million times a second as there is no Sync() apparent!

-- Jim - When is there going to be a release?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Aug 2014 05:15
I would also suggest looking into using only std::String to do string things. It does pretty much all garbage collection and string management.

Also, very important for memory leaks, any AppGameKit command that returns a string (shows char* as the return type in the help pages) is dynamically creating that string every time and it is up to us to release the memory.



It is important to use 'delete[]' because the strings created are made using 'x = char[99];' (The '99' is just an example.)

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-05-13 15:22:38
Your offset time is: 2024-05-13 15:22:38