Maximum recursion level

Hello everyone, during implementation of ‘qsort’ sort method for arrays in C/AL i’ve encountered an interesting problem. Tis a maximum recursion level of function calls. It was obtained to be equal to the figure 637 (638 calls inside Attain object - auxilliary report). But i’m not absolutely sure in this number. It is due to absence of information about function calls management by N/F. E.g., i don’t know precisely is it number limitation or some memory limitation. I’d be very gratefull for any comments concerning question. (my ver.N/F 3.60 SP4/3.10) P.S. As i know how to avoid this problem - just to not use recursion - tis more question then problem. Happy new year, mary xmas Anthony

I’m using recursion a lot. It works great. Maybe your problems come from lack of available RAM or improper use of global/local variables? You could try to post some code, to let us help you.

Thanks for your input, it is ordinal qsort method for different report presentations. I’ll be not original writing: ///----- “QuickSortL(First ,Right-1,Relation,Level);” -----\\ IF First<Last THEN BEGIN Pivot:=First;Left:=First+1;Right:=Last; REPEAT KeyCon:=TRUE; WHILE(Left <=Right)AND(KeyCon=TRUE)DO BEGIN KeyCon:=NOT CorrespRelation(ArrToBeStd[Pivot],ArrToBeStd[Left ],Relation); IF KeyCon THEN Left +=1;IF Left>Right THEN KeyCon:=FALSE; END; KeyCon:=TRUE; WHILE(Right>=Left )AND(KeyCon=TRUE)DO BEGIN KeyCon:=CorrespRelation(ArrToBeStd[Pivot],ArrToBeStd[Right],Relation); IF KeyCon THEN Right-=1;IF Left>Right THEN KeyCon:=FALSE; END; IF Left<Right THEN ExchangeVA(Left,Right); UNTIL Right<Left; ExchangeVA(Pivot,Right); QuickSortL(First ,Right-1,Relation,Level); QuickSortL(Right+1,Last ,Relation,Level); END; ///----- “QuickSortL(First ,Right-1,Relation,Level);” -----\\ where ‘CorrespRelation’ is function for needed array reorder. Sorted arrays are global variables inside auxilliary report. The maximum level of recursion is reached for array inversion job. It is particular and artificial case for test. In this case the array consists of it’s indices and the task is to reverse it. It results in ‘one side tree’ of calls which reaches mentioned figure for size 637 or for total number of calls 638. The question just about N/F. Is it number limitations or memory limitation? For instance it may be specified somewhere in paramaters and i just don’t know where it! Thnk you, Anthony

I should add that call of function performs like ‘QuickSortL(First ,Last,Relation,Level)’. Can it be some another case for report use limitation? I use it for calls of its methods.

Hi kopyurff, I made a small recursive function AddUp, which works like this: AddUp(5) = 1 + 2 + 3 + 4 + 5 = 15 The code looks like this: OnRun() Win.OPEN( 'Enter number #1########\' + 'Result is #2########'); REPEAT Win.INPUT(1, Num); Win.UPDATE(2, AddUp(Num)); UNTIL FALSE; AddUp(I : Integer) Res : Integer IF I <= 1 THEN Res := 1 ELSE Res := I + AddUp(I - 1); Max limit on my PC before I get a stack overflow is 721. Try the code and see if your max is 721 as well. Conclusions: (1) I don’t think there’s an exact number for the upper limit of recursive calls - it’s a memory (stack) limitation. (2) Recursion in C/AL should be done with care or most likely avoided.

Couldn’t you create a table with some keys and use a temporary version of that table like a stack to handle your recurrsion? Then you have much more ‘memory’ to access. Django

Thanks a lot for your new number at the new year eve! I truly thought that it’s rather usefull to share this question and to ask for some opinions… One of the reasons for asking is probable dependance of this value with some Attain system parameters or with, e.g., system version. So as i understand, this parameter should be obtained for each recursion implementation empirically and after it application will be stable with more or less reliability. Also ‘obtained figure’ does not depend on use variable parameters of function - it means system doesn’t copy them in memory but apply some kind of pointers. But it hits productivity nearly 1.2-1.5 times comparing to use of global variables. In this case it is a pair of arrays with the length 10000 (pretty big number and variable). One of them is used for referrence another one for returning ‘right’ order of the elements. Thanks a lot for an idea with temporal table. Perhaps tis more difficult for realisation. In any case i’m on the track of implementation of the shell sort. It can be applied for subarrays at critical level of calls and has rather efficient algorithm. So i have solution without tables. BR, Anthony

No problem. Glad you’ve found a solution. It’s still noon on New Year Eve here. 12.5 hours to go until next year… :slight_smile:

Hi SV, your function gave me the maximum number 728. I called it with the aim of Req.Form button (code ‘OnRun’ was removed into ‘OnPush’ trigger). Previous test was performed on different PC and gave me the same result. Therefore tis value not PC hardware dependable but only hangs on N/F system version (in my opinion). Thank you, Anthony

Hi all, … And it gives “865” in version 3.70A. All parameters including PC were equal. Old question but new system version. Regards