Bug? Stackbuffer grows up extremely

Siam

Active Member
Licensed User
Longtime User
hi

i dont know if this a bug or a feature ;)

with this little program the stackbuffer goes over 3000 !?
is there a possibility to clean the stack between this loop?

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 3100
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    For t = 1 To 256
        Log (Asc(t))
        Log("stack :",StackBufferUsage)
        
        Delay (100)
    Next
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is not a bug.

1. You are not using Asc correctly. Asc expects a string. I think that you are actually looking for Chr which doesn't exist in B4R because strings are arrays of bytes.

Correct code:
B4X:
Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   Dim b(1) As Byte
   For t = 1 To 256
       b(0) = t
       Log(b)
       Log("stack :",StackBufferUsage)
       Delay (100)
   Next
End Sub

2.
is there a possibility to clean the stack between this loop?
Yes. Not relevant here but you can put the loop inner-code in a different sub and call it. This way the stack will be released every iteration.
 
Top