Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tutorial] RAII explaination and usage.(deleted due incorrections)

Elite Diviner
Joined
Feb 28, 2013
Messages
401
Reaction score
145
Thanks for your effort but can you discuss it more because i really doesn't understand your topic clearly like what is the purpose of this codings for example ?

Kind Regards,
ItsTaP.
 
Junior Spellweaver
Joined
Oct 8, 2005
Messages
121
Reaction score
23
this calling examples show you how to declare an IF statment when it release itself(the memory) and this technique called RAII.
another simple thing you can do is just using free(); ,to the address you pointed , or the release from XEAx post.

i gave the source site becouse it has more examples of code that you can understend it better.
 
Junior Spellweaver
Joined
Oct 8, 2005
Messages
121
Reaction score
23
You really did not capture the essence of RAII, which is also described the linked reference. Plus, your explanation is almost impossible to understand. Maybe it's a language issue.

Anyaway, RAII is described in the bullet points.


The thing about resource is, that you must always release them once you're done with them. Many languages have constructs for that, e.g. a with block in Python or a try-finally block in Java. In C++ you often use RAII, which can be used in all object oriented languages. This ties the lifetime of the resources to an object. The lifetime of the objects are in-turn managed by the language, most often the stack or some sort of smart pointer. In the above example it is the stack.

In C++ when you create an object in a block (e.g. a function) without explicitly putting it on the heap (e.g. with new), it will be on the stack and its destructor will be called once the instruction pointer leaves the block. This ensures that the resources are freed. This is the reason you do not call any explicit unlock function in the good function of the above example. The compiler inserts those.

The first example is bad because if the if-statement evaluates to true, you return and you'd never hit that free, therefore your muted would be locked. This could be very difficult to find in a larger code base.

Maybe it is a language issue ,
working on my english,
i did not implemented it yet but i want to.
when ill finish ill give an example of skill that i changed.

on my files atm i used Xeax guide and free((void*)theObject) -- ofc theObject is changed to the object i created in the file.
but it long and have alot of places that can still be leaked.
in my opinion - when we start to understend it together the community will grow and we will see wonderful results.
for example - look at MuOnline forum, they have tons of players and tons of files and resources. thats becouse they helping each other.

i appriciate that you share your knowladge with us.
Thanks.
Hope ill can help you guys back soon ;)
 
Back
Top