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
964
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top