Code: Select all
' Tickle a segfault
const NUMDATA = 50000 ' Segfault(!)
'dim as integer NUMDATA=50000 ' OK
dim as string sQ(NUMDATA)
dim as string sB(38000) ' 37000 OK. 38000 Segfault(!)
Code: Select all
' Tickle a segfault
const NUMDATA = 50000 ' Segfault(!)
'dim as integer NUMDATA=50000 ' OK
dim as string sQ(NUMDATA)
dim as string sB(38000) ' 37000 OK. 38000 Segfault(!)
Code: Select all
const NUMDATA = 50000
redim as string sQ(NUMDATA)
redim as string sB(38000)
Code: Select all
const NUMDATA = 50000
dim as string sQ(NUMDATA + 38000)
Indeed. I haven't checked how fbc performs constant folding, but using a constant and a literal in the dimensions does produce an array in the stack (since the expression ends up being constant as well). Note that this is effectively what fxm's code does (he uses redim instead of dim). Another way of expressing that could be:
Code: Select all
const NUMDATA = 50000
dim as string sQ()
redim sQ(NUMDATA + 38000)
fxm wrote: ↑Sep 27, 2020 6:48Furthermore, I am not talking here about taking into account the procedure calls (with saving registers and passing parameters) which are generally very numerous and therefore very nested. And what about recursive calls!fxm wrote:The FreeBASIC compiler does not add code to check at runtime the available memory in the system stack (even with the -exx compile option).
Only at compile time it roughly estimates if for each local static array there is no overflow of the system stack but without taking into account the stack memory needed for other local variables in the scope (including the other local arrays in the scope).
Compiler warning occurs only for each local static array strictly greater than the complete system stack size.
Otherwise, see FAQ: Why does my program crash when I define an array larger than xx?
With Quicksort having an average complexity of O(n*log(n)) and Bubblesort having an average complexity of O(n²) this can't really be true in general. Maybe you have special data (e.g. already roughly sorted) or your implementation is somehow buggy.
Code: Select all
D:\compiler108\freebasic64bit\fbc64_gas64 -R -v -gen gas64 test_stack.bas
FreeBASIC Compiler - Version 1.09.0 (2022-01-09), built for win64 (64bit)
Copyright (C) 2004-2021 The FreeBASIC development team.
standalone
target: win64, x86-64, 64bit
backend: gas64
compiling: test_stack.bas -o test_stack.asm (main module)
test_stack.bas() error 0: STACK OVERFLOW, review array size, use redim/shared or increase stack size, for proc=main"
Code: Select all
Begin of procedure
add totalSizeStack,procSizeStack
cmp totalSizeStack,maxSizeStack
jg label
call errorRuntime
labal
End of procedure
sub totalSizeStack,procSizeStack