Snippet Alloc

tooltiperror

Super Moderator
Reaction score
231
>Things like this are just not possible:
Well, they are, but you don't have typesafety. Which, IMO, is good. I like the idea of a more dynamically typed language.
JASS:
struct Card extends array
    method play takes nothing returns nothing
        // the usual card playing
    endmethod
    implemnent Alloc
endstruct
globals
    private Card DEFAULT_CARD=Card.create()
endglobals

struct SpecialCard extends array
    delegate Card DEFAULT_CARD
    method play takes nothing returns nothing
        // special card playing stuff
    endmethod
endstruct

function PlayCard takes integer card returns nothing
    call card.play()
endfunction


You COULD do some typesafety if you wanted, that's child's play.

Ignore Nestharus for the most part, he thinks JASS is C.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
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.

i was under the impression that this system was intended for users whose goal was speed (because they were doing heavy computations or lots of allocations / deallocations or w/e)
 

lep

Active Member
Reaction score
8
>Things like this are just not possible:
Well, they are, but you don't have typesafety. Which, IMO, is good. I like the idea of a more dynamically typed language.
Sure a dynamic language is fine. But there are some points regarding this.
At first: Jass is no dynamic language. It is no dynamic language. Period.
And, i have the feeling that there are only dynamic languages because there is no
good typesystem.
Haskells typesystem is kinda fine. It's highly strong typed but a really dynamic language.
Haskellers often say, that once your program compiles it also works properly because of its strict typesystem.

JASS:
struct Card extends array
    method play takes nothing returns nothing
        // the usual card playing
    endmethod
    implemnent Alloc
endstruct
globals
    private Card DEFAULT_CARD=Card.create()
endglobals

struct SpecialCard extends array
    delegate Card DEFAULT_CARD
    method play takes nothing returns nothing
        // special card playing stuff
    endmethod
endstruct

function PlayCard takes integer card returns nothing
    call card.play()
endfunction


You COULD do some typesafety if you wanted, that's child's play.

You are trying to solve problems you created yourself. In the first way there was no
need for this.

And i don't think this works
JASS:
//...
function PlayCard takes integer card returns nothing
    call card.play()
endfunction


Calling a [ljass]method[/ljass] on an [ljass]integer[/ljass]. You have to typecast it.
So you loose all your abstraction since you have to specialize on a concrete type.
Kinda works against the principles of Polymorphism.

Ignore Nestharus for the most part, he thinks JASS is C.
Problem is that Jass is neither C nor Ruby.



i was under the impression that this system was intended for users whose goal was speed (because they were doing heavy computations or lots of allocations / deallocations or w/e)

The speed gain is really negligible. And if you do some special operations in a tight loop you probably aren't using normal structs with normal allocators anyway. Either use allready existing structures or maybe precomputed values.

For normal spell-making there is no need for this.
 

Nestharus

o-o
Reaction score
84
eh, for tight operations when using structs, I just inline the allocate/deallocate call and it's 100% exact same code >.>.

So for tight operations, you'd still be using this >.>.

Also keep in mind that most of the time you don't need polymorphism. In fact, you never need full blown polymorphism. Usually there is only one little thing in one method that needs to be polymorphic, and that's generally in a timer or a trigger already, so no need for interfaces. This is ofc if you are squeezing out every last ounce of performance =).

Polymorphism is nice to have in a language if it actually works right, but polymorphism in JASS is slow cumbersome triggers.
 

Sevion

The DIY Ninja
Reaction score
413
It seems I can't use StopWatch Natives on 1.26. Bummer.

I can't put this argument to rest until I can use StopWatch.
 

Nestharus

o-o
Reaction score
84
vJASS style, 5fps for 1500 instances (create/destroy)
JASS:

globals
    integer a = 0
    integer array b
    trigger t = CreateTrigger()
endglobals

function D takes nothing returns boolean
    return false
endfunction
function E takes nothing returns boolean
    return false
endfunction

function B takes nothing returns nothing
    local integer c
    local integer x = 100
    local integer k
    loop
        exitwhen x == 0
        set c = b[0]
        if (c == 0) then
            set c = a + 1
            set a = c
        else
            set b[0] = b[c]
        endif
        set k = c
        set b[c] = b[0]
        set b[0] = c
        call TriggerEvaluate(t)
        set x = x - 1
    endloop
endfunction

struct tester extends array
    private static method onInit takes nothing returns nothing
        local integer x = 15
        call TriggerAddCondition(t, Condition(function D))
        call TriggerAddCondition(t, Condition(function E))
        loop
            exitwhen x == 0
            call TimerStart(CreateTimer(), .031250000, true, function B)
            set x = x - 1
        endloop
    endmethod
endstruct


Alloc style, 15 fps for 10,000 instances create/destroy
JASS:

globals
    integer a = 0
    integer array b
endglobals

function B takes nothing returns nothing
    local integer c
    local integer x = 500
    loop
        exitwhen x == 0
        set c = b[0]
        if (c == 0) then
            set c = a + 1
            set a = c
        else
            set b[0] = b[c]
        endif
        set b[c] = b[0]
        set b[0] = c
        set x = x - 1
    endloop
endfunction

struct tester extends array
    private static method onInit takes nothing returns nothing
        local integer x = 20
        loop
            exitwhen x == 0
            call TimerStart(CreateTimer(), .031250000, true, function B)
            set x = x - 1
        endloop
    endmethod
endstruct
 

Romek

Super Moderator
Reaction score
963
The issue isn't that people don't believe you that it's faster. It's easy to see that it's faster than the standard struct allocation.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
@Nestharus :

Wrong copy/paste or what ?

Coz, i don't see where do you compare struct allocations here, just 15 periodic timers calling a function, and 20 periodic timers evaluating a trigger which contains 2 empty conditions which returns false.

Honestly that just should be the part from vJass, i don't see the point of the extra checks of default vJass struct allocator, if you use an invalid struct instance your map is already broken anyway.
 

Sevion

The DIY Ninja
Reaction score
413
The issue isn't that people don't believe you that it's faster. It's easy to see that it's faster than the standard struct allocation.

Not trying to convince that it's faster, rather how much faster. With this, it's approximately 6.67x faster.

Troll-Brain, he's comparing the methods, not the actual code itself.

They are one and the same (check generated code on structs extending another struct and Alloc structs using delegates).
 

Nestharus

o-o
Reaction score
84
Actually, I was being nice to vJASS. It has even more overhead.

It evaluates a trigger array, not a trigger.

I'd need to look at struct initialization to see what's added to the trigger. I'm not sure, but I think that nothing is added to the trigger if onDestroy doesn't exist. If it does, then the functions or w/e are added to the trigger. But again, I am 100% unsure since I've never looked at vjass struct initialization =P

Anyways.. someone else can look, but that just means that vjass is actually slower than what that little stress test thingie showed =D

It also has this for types
set si__a_type[this]=1
 

tooltiperror

Super Moderator
Reaction score
231
6.67% speed increase is noticeable if these are running in a T32 callback, for example.

This is written good, safety is safe, and I've used it myself :thup:

Approved.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • 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 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