Snippet Alloc

Nestharus

o-o
Reaction score
84
onDestroy needs to be called inside of a trigger evaluation.

There is a reason why it is done that way in vJASS.

edit
JASS:

struct Guard
    static method create takes nothing returns thistype
        set guard = CreateUnit(...)
        return this
    endmethod
    method onDestroy takes nothing returns nothing
        call RemoveUnit(guard)
        set guard = null
    endmethod
endstruct

struct UnitGuard extends Guard
    static method create takes nothing returns thistype
        call AddSomeCoolEffect(guard)
    endmethod


Notice that with your current design, onDestroy in Guard would not be called if UnitGuard was destroyed. This is the reason why there need to be trigger evaluations. Each instance would get a trigger and as the things are created, the onDestroy things would be piled on to that trigger. When destroy is called at any of the instances, the trigger is evaluated, meaning that all of the stuff gets properly destroyed.

If you are supporting onDestroy, you need to do that because that is what it traditionally does in vJASS.

People would be doing inheritance via delegates, meaning that you end up registering and doing all sorts of other nonsense.

I suggest just taking onDestroy out and leaving it up to the user to call it however they wish.
 

Sevion

The DIY Ninja
Reaction score
413
I suppose taking it out makes sense.

I wasn't sure how to go about using delegates to do all of this stuff.

However, when using Alloc you shouldn't be directly extending other structs anyways. All structs should just be an array struct.

I'll just take out OnDestroy functionality and leave it up to the user.

Updated to 1.04.
 

Sevion

The DIY Ninja
Reaction score
413
Updated to 1.05, fixed some debug things that Anitarf suggested and added null entry deallocation protection.
 

Bribe

vJass errors are legion
Reaction score
67
With the null instance protection and the 8190 protection enabled, your module is now just as slow as Vexorian's structs, stripping away the advantage entirely. Safety should only be optional, not mandatory. That's the problem with wc3c.net, they really love their verbosity.

Really, this is 99.99% useless now with that enabled.
 

Sevion

The DIY Ninja
Reaction score
413
Reverted to 1.04 with the exception of keeping null entry deallocation in there (in debug mode only).

It will not run the same as default structs (except for onDestroy) when in debug mode and faster in release mode.

Still no moderator reviews?
 

Romek

Super Moderator
Reaction score
963
The OnDestroy addition was quite useful, I think.
You can't properly extends structs whilst using this anyway (and if you want to, just use the standard structs instead of this), and I think this is aimed at people who just want a single data struct or something without inheritance and any other fancy stuff.

> If you are supporting onDestroy, you need to do that because that is what it traditionally does in vJASS.
This entire thing doesn't do what's 'traditionally' done in vJass anyway.
 

Sevion

The DIY Ninja
Reaction score
413
OnDestroy can be done by the end user in the destroy method.

This is more aimed at system makers that need extra efficiency on allocation and deallocation. AIDS for example could benefit from something like this. If there is a large amount of units created/removed any amount of efficiency gain is nice.

I suppose that if I do add OnDestroy it'll more or less make it just like an unsafe vJASS struct, which would be pointless in the end.

Update: Reverted the code to exactly the same as 1.04 (except for the debug message in deallocation).
 

tooltiperror

Super Moderator
Reaction score
231
I don't think anything should extend other structs or interfaces. I believe all inheritance and polymorphism should be done through taking integer parameters and the use of a delegate(s), so this is a logical addition for structs.

All structs should be array structs.
 

Sevion

The DIY Ninja
Reaction score
413
Update: Moved the overflow check so it only checks when the instance count increases. Efficiency gainz are over nine thousaaaaaand!
 

lep

Active Member
Reaction score
8
[...]
Safety should only be optional, not mandatory. That's the problem with wc3c.net, they really love their verbosity.

[...]

Talking about verbosity, you want me to type [ljass] extends array[/ljass] and
[ljass]implement Alloc[/ljass] and
JASS:

        public static method create takes nothing returns thistype
            return thistype.allocate()
        endmethod

        public method destroy takes nothing returns nothing
            call this.deallocate()
        endmethod
for every single struct i create?!
(Taken from the "Demonstration" from the op [1][2].)
And not to forget that i neither can use [ljass]interface[/ljass]s nor normal
inheritance.

And let me get it right: i have to do all this to get speed-improvement of like
two less [ljass]if[/ljass]-statements and one assignment per instance-lifecycle?!

Well, uh, for me that sounds like a bad deal.

________
[1]: http://www.thehelper.net/forums/showthread.php/163457-Alloc
[2]: The original code:
JASS:

    private struct teststruct extends array
        implement Alloc

        private string data

        public static method create takes nothing returns thistype
            //call BJDebugMsg("Created")
            return thistype.allocate()
        endmethod
        
        public method test takes nothing returns nothing
            call BJDebugMsg("Instance: " + I2S(this))
        endmethod

        public method destroy takes nothing returns nothing
            call BJDebugMsg("Destroying: " + I2S(this))
            call this.deallocate()
        endmethod
    endstruct
 

tooltiperror

Super Moderator
Reaction score
231
This should use a delegate like AIDS does. As lep pointed out, redeclaring [LJASS]create[/LJASS] and [LJASS]destory[/LJASS] for a struct that simply needs to be allocated out of scope is a waste of space. Just add in this.
JASS:
private struct DEFAULT_ALLOC extends array
    method destroy takes nothing returns nothing
        call this.deallocate()
    endmethod
    static method create takes nothing returns thistype
        return thistype.allocate()
    endmethod
    implement Alloc
endstruct
globals
    private DEFAULT_ALLOC DEFAULT
endglobals


And then just add in [LJASS]DEFAULT[/LJASS] as a [ljass]delegate[/ljass]. That saves six useless lines.

And WC3C really is a verbosity loving site. I mean, which THW we get crap like [LJASS]x.create(10,"temp",this.unit,24,"some\\special\\effect\\mode.mdx")[/LJASS].
 

Sevion

The DIY Ninja
Reaction score
413
You don't need to declare create and destroy.

You can just use allocate/deallocate directly.
 

lep

Active Member
Reaction score
8
You don't need to declare create and destroy.

You can just use allocate/deallocate directly.

Nah, that's no real option.
As soon as i want to do some stuff at initialization i have to write a create [ljass]method[/ljass]. So in my first version of my script i don't need a [ljass].create[/ljass] so i use [ljass].allocate[/ljass] all through my code.
The something changes and i need a create [ljass]method[/ljass]. Now i have to
change my whole script for a thing JassHelper does for free.

And all that hassle for two missing [ljass]if[/ljass] statements and no errorchecking...
Yeah, no, thanks.

And if you want to reduce the sloc generated why not use a single counter for all structs, eh M;D
When nobody overflows anyway...
 

Sevion

The DIY Ninja
Reaction score
413
I don't think you understand, lep.

We don't use a single counter for all structs because it would not support recycling which would make overflowing happen a lot more often.
 

lep

Active Member
Reaction score
8
I don't think you understand, lep.

We don't use a single counter for all structs because it would not support recycling which would make overflowing happen a lot more often.

last two lines were sarcasm.
Maybe i should use the Sarcasm Tag.

And it would support recycling...
And do you think you have at any time more than 8190 struct instances?
That actually would be a good reason for a custom allocator, to do some analyzing
logs.

It's nice that you seem to care for overflow in that case but not in the regular case.

meh, i would never use this anyway but noobs shouldn't get fooled with this "SPEED MEGA OPTIMIZATION" where every unit creation is probably slower than a struct alloc/dealloc cycle.
 

Nestharus

o-o
Reaction score
84
/yawn

the primary reason people write structs that extend arrays is to avoid the trigger spamming that jasshelper structs do when you extend off of them >.>.

you seem to have ignored that statement that when calling the destroy method, it evaluates a trigger if there are any struct extensions involved.

it's just much smarter to use delegates >.>.

it also generates a useless line or w/e

read more here
http://www.hiveworkshop.com/forums/...ls-280/coding-efficient-vjass-structs-187477/
 

lep

Active Member
Reaction score
8
/yawn

the primary reason people write structs that extend arrays is to avoid the trigger spamming that jasshelper structs do when you extend off of them >.>.

you seem to have ignored that statement that when calling the destroy method, it evaluates a trigger if there are any struct extensions involved.

Hey, if you want to reduce code-spamming just use a single alloc-method.
And personally i see no problem in "spamming" those triggers. It's a nice
way to dynamically call [ljass]function[/ljass]s in Jass.
And better not come with herp derp speed.
A normal map will not suffer from inheritance. And if you do some heavy computations
you will neither use normal structs nor the system in this thread.


it's just much smarter to use delegates >.>.

And this method described in here can't really use inheritance at all, since
you're encouraged to use [ljass]delegate[/ljass]s.
That way you loose the abstractation of [ljass]interface[/ljass]s.
Things like this are just not possible:
JASS:

interface Mover
				method move takes real x, real y returns nothing
endinterface

function AddToMovers takes Mover m returns nothing
//...
endfunction


For me correct types and abstractions are way more smarter than than
destroying type safety and error-checking.

You guys seem to focus way more on the specialisation than on abstractation.
And ofc on negligible speed performance.
(Not to mention all that hassle i allready pointed out to just use this method.)

it also generates a useless line or w/e
Oh noes, that will totaly kill my map.
If this bothers you so much and Wc3Optimizer doesn't removes it, it's easy
to just write a like three-line script to remove that particular lines.


It's not like i don't know what's JassHelper's doin'...

JassHelper does a kinda good job to give us a higher-level language and you are
killing it with these things.
All those Boilerplatecode for doing simple things JassHelper does automatically.
No. No. No need for this.

And how goes that quote again?
Premature optimization is the root of all evil.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      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