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.

Dark GDK / New to C/C++? Confused about working with strings? Read here.

Author
Message
Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 13th Sep 2007 10:27 Edited at: 13th Sep 2007 11:00
Hello all. I made a string library for controlling strings. In DBP people are probably used to stuff like: a$ = "Hello " + b$

Well, in C/C++ this is a bit more difficult to do. I've created a string library (IString) which helps you get past this. I know there is already std::string, but I decided to build one myself anyways.

Here it is:


I don't have DGDK, but I believe this would be workable code:



Enjoy.

Cheers,

-naota

DBP, $80. DBP's plugins, $320. Watching DBP Crash, Priceless.
NG Website Aex.Uni forums
unitech
17
Years of Service
User Offline
Joined: 27th Jun 2007
Location:
Posted: 13th Sep 2007 15:08 Edited at: 13th Sep 2007 17:21
Nice.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 13th Sep 2007 23:00
Like the Token Part - I did something similiar - (Making a class - not the token part.. need to scopre that out) Also going to study your class and see if I'm doing things right (Seem to be but.. there is a weird thing I had to do to get ConCat to work and I'm not sure why...)

EXCELLENT WORK! I (And unitech evidently) Appreciate it! Good Job! (Now get DarkGDK C++ and switch to the dark side)

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Sep 2007 01:16
The problem with the NIH syndrome (Not Invented Here) is that you usually end up with slower and incorrect code.

Sorry if it seems like I'm trashing your code here, but this class really needed a lot more work before it was released to the public as a usable alternative to std::string.

You need to check for bugs here:
Append - Incorrect length for new string, limited size of strings.
Compare - You only check for NULL in one of the strings.
GetToken - Non-repeatable, trashes your string, cannot run two or more tokens side-by-side for different strings.
No copy constructor/operator= - if you copy an IString to another, both will free the memory either during append or destruction.

Speed:
You check the string length almost everywhere (std::string doesn't).
Unnecessary memory accesses - blanking memory then writing over it (Left/Right/Mid), copying when not needed (Append)

Usability:
No safe copying (no copy constructor/operator=), no operator overloading (+, =, [] etc), no protection for the string contents (everything is public), access is all via pointers (why not pass by reference?)

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Sep 2007 03:00
Go IanM!

Ha ha - I still think he did a very nice thing though - and I didn't know about the strtok function - but you just told me how to be careful with it! Thanx for all the above!

Like I said I've written my own as well - and it is a good learning exercise and frankly I don't have the operator overloading stuff either - no reason - just didn't get to it. I'm sure when I get tired of MyString.ConCat("New Stuff to append") and want stuff like MyString=MyString+"More"; or MyString+="More" I'll do it.

At work - I can't do the NIH syndrome myself because there isn't time - but HERE - making Games? I think its fun. I used to program assembly language alot though so I'm always trying to apply things learned there here

I for one do appreciate you piping up - not cause your a mod and all that - but cuz you do throw out some cool code suggestions etc.

@Aaron Miller - Don't be discouraged - Check what IanM said cuz these "simple little" routines (That you end up using thousands of times) need to be more perfect than the game in my opinion because a little memory leak or unanticipated pointer - at run time - means "Access Violation". I for one appreciate all code snippets good and bad because I don't use them verbatim anyway... I study them and try to learn from them and I think if everyone does that - keep the good toss the rest - we all can learn alot.

Keep Hacking Man - It's how you learn!


Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 14th Sep 2007 03:11
@unitech
Thanks.

@jason p sage
Thanks. I was planning to use this for some parsing operations actually, however in both a game and parser, these operations must be perfected.

@IanM
I thank you for your input, it will allow me to make this library better, and hopefully much more usable. As for the operator things, I never got around to learning about how those commands work, I never found a need for them. Course the public does find them to be nice, so I'll go ahead and see what I can do.


Cheers,

-naota

DBP, $80. DBP's plugins, $320. Watching DBP Crash, Priceless.
NG Website Aex.Uni forums
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 14th Sep 2007 03:20
Its basically the same thing as functions etc - but you have to define them specially - check this out:

http://www.cplusplus.com/doc/tutorial/

There is a link all about it.

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Sep 2007 13:39
Quote: "but HERE - making Games? I think its fun"

Agreed, I do it myself too so that I can understand how it works - it's how I learn.

@Aaron,
I'm looking forward to seeing what you produce, and I'm glad I haven't discouraged you from continuing with this.

If I can help in anyway, let me know via email.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code

Login to post a reply

Server time is: 2024-10-08 22:18:26
Your offset time is: 2024-10-08 22:18:26