onDestroy and destroy

Ayanami

칼리
Reaction score
288
Is there a difference between these two? I do know that onDestroy is ran right before the struct instance is recycled. However, wouldn't onDestroy be pointless when you could just override the destroy method? Or am I missing something?
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
However, wouldn't onDestroy be pointless when you could just override the destroy method?

Yeah, it is. One (onDestroy method) generates a trigger, the other doesn't. Use a custom destroyer with .deallocate(), unless you really need to use onDestroy. :p
 

jackall

You can change this now in User CP.
Reaction score
37
oww maan! vJass looks so over-complicated to me!! im not gonna use it anymore!!! ever!!!! :D
not really..... im gonna try using it as much as possible!!!!!!
 

Jesus4Lyf

Good Idea™
Reaction score
397
Create --> Allocate.
Destroy --> Deallocate.

This means if you use a custom allocation scheme, you can make destroy not "double free" the "struct" (excuse the confusing "s).

Example:
JASS:
struct Zomg
    static method create takes player p returns thistype
        return GetPlayerId(p)
    endmethod
    method destroy takes nothing returns nothing
    endmethod
endstruct

In this you don't need to deallocate since you never allocate - structs being integers means you can define an allocation scheme like this. This struct would inline the create method to GetPlayerId, and look up fields against that player id, basically. In fact, you wouldn't need to destroy it, but for users' sake, at least if they try to, they won't get a nasty error message. Of course, you could flush values or something in the destroy method, still. :)
 

Nestharus

o-o
Reaction score
84
onDestroy is there for polymorphism.

Let's say that a struct extends another struct.
[ljass]struct b extends a[/ljass]

If an instance of struct b is stored as struct a and is destroyed, then the proper destruction methods are called (the trigger is there so that it can call the correct destruction method).

If the plain destroy is used, then storing b as struct a and destroying it will call a.destroy() rather than b.destroy(), thus calling the incorrect destruction method.

Polymorphism may seem cool, but it comes at a heavy price.

The fact is that onDestroy will be called regardless when extending structs. If you want to get away from polymorphism, then you have to turn to struct arrays and delegates.

See http://www.hiveworkshop.com/forums/...ls-280/coding-efficient-vjass-structs-187477/
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top