Macro vs sub

Home » Asterisk Users » Macro vs sub
Asterisk Users 4 Comments

Hello list,

can I conclude that it is better to use sub’s in stead of macro’s ?

I read the following in an Asterisk-book :

GoSub() works in a different manner from Macro(), though, in that it
doesn’t have the stack space requirements, so
it nests effectively. Essentially, GoSub() acts like Goto() with a
memory of where it came from.

Is it then not better to use a method that does not stack ?!

4 thoughts on - Macro vs sub

  • Jonas

    From what I understand they are trying to phase out Macros. We are slowly removing them from our dialplans as time allows for testing.


    Bryant Zimmerman (ZK Tech Inc.)

    616-855-1030 Ext. 2003

  • Can someone confirm that the nesting of macro’s or the continuous and
    simultaneous use of different macro’s, can lead to stack-problems and
    cause an Asterisk spontaneous reboot/restart ?

  • How would I notice that this is really the case here ?

    I should see the RAM-memory spike on the server ? I do not see this…

    Webmin says : 3.83 GB total, 375.51 MB used

  • Hi, why don’t you try write two macros only and recursively call both of
    them incrementing a counter each time you call the inner macro. Also
    print(NOOP) system stats along with the counter. You’ll soon see what

    The para Matthew quoted is cent percent true. But if you don’t need to
    call macros within macros and do kind of recursove macro calling then you
    can continue using macros safely.

    Its not that I never use macros at all, I only use where I know I’ll get in
    macro and safely exit without going any deeper within the dial-plan.