Sign in to follow this  

Registering a custom string class

This topic is 2787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been trying to register my own string class named asString in AngelScript, and I have a couple questions. I originally encountered a segmentation fault when using operator+ with my class (by the way, I run Linux), but when I changed the operator+ function to have a return type of asString * instead of asString it worked. Why is that? Shouldn't that cause memory leaks? For example: string a = "Hello "; string b = "world!"; string c = a + b; Wouldn't that leak memory, and not work as well, since c is of type string and "a + b" is of type string *? Unless there's something I'm not understanding about AS and/or pointers. But it compiles and runs fine. By the way, it's the same situation with asIScriptEngine->RegisterStringFactory. Thank you for your help. EDIT: Oh yeah, I forgot to say that asString is a reference type.

Share this post


Link to post
Share on other sites
All string are internally asString*, and asString are reference counted (did you do that? ... because it was supposed you to do it).

http://en.wikipedia.org/wiki/Reference_counting

Share this post


Link to post
Share on other sites
Oh, okay, I get it now. So then all reference types are dynamically allocated, and are deleted when they have no more references? I did make asADDREF and asRELEASE behaviours, by the way. I was just getting confused because I was seeing new without a nearby delete and the tutorial I was reading didn't explain it well.

Share this post


Link to post
Share on other sites

This topic is 2787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this