Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now
- - - - -

Object Handle vs Object reference

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Oscar1   Members   


Posted 15 May 2013 - 06:51 PM

Since I can use Object reference as parameters in my functions and the object handle is in fact NOT a pointer, is there really any reason of using (or even having) object handles? I just can't find that good reason.


The only difference I see is that I can reseat the object handle with different object and I can also use it as a return parameter of function.


I really don't know, I wanted to wrap my head around the need for object handles - especially the reason why I would want to use them, but since I can pass reference in functions, I can't find any reasonable reason to use them.

Is there some safety issue, speed issue or something else? Is there something obvious I don't see?


Give me some ideas. Thanks. Love the angelscript, I just want to understand it better.

Edited by Oscar1, 15 May 2013 - 07:01 PM.

#2 FDsagizi   Members   


Posted 16 May 2013 - 09:53 AM

obj ref - use ref couner to variable, if ref count > 0 varialbe is live!
obj handle not use this and can be not a valid.

Edited by FDsagizi, 16 May 2013 - 09:54 AM.

#3 saejox   Members   


Posted 16 May 2013 - 02:14 PM

They are very different. You cant assign a reference for example.

Handle is a safe refcounted/garbage collected pointer, ( like shared_ptr in c++ but safer )

Reference is same as reference in c++ but not assignable.


void Func( Object &obj )


   Object &o = obj; // not possible in angelscript


#4 Andreas Jonsson   Moderators   


Posted 17 May 2013 - 07:19 PM

The difference is similar to * and & in C++. A handle @ can be null, but a reference & can't be null. A @ can be reassigned to point to another object after initialization, a & can't be reassigned.


In C++ to declare a function that returns a new object in an argument you would write something like this:


void CreateObject(obj **);


In AngelScript the same would look like this:


void CreateObject(obj@ &out);


When declaring a function in AngelScript to take a @ as argument you're telling the caller that the argument can be null, and when you declare the argument as & then you tell the caller that the argument cannot be null and must be given a valid object. In C++ you tell the same thing with * and &.


There is no difference in safety. AngelScript is a sandboxed (at least if the application only registers types and functions that behave properly), so both @ and & are equally safe and neither will result in risk of memory leak or dangling pointers, etc.


There can be a slight difference in performance when using one over the other, but it is not something you should be counting on as it can vary a lot from situation to situation.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.