[Gambas-user] Gambas has Gosub now!

Benoît Minisini gambas at ...1...
Tue Mar 6 02:00:27 CET 2012


Le 05/03/2012 18:28, Emil Lenngren a écrit :
> It is no strange at all that stack reallocation is slower and slower
>  as the recursion gets deeper. Because when the stack has to be
> resized, a new memory area is allocated and the old stack is copied
> over to the new, and the old gets freed. As the recursion gets
> deeper, more and more data has to be copied each time.

Indeed. But I found it very slow when I did my test. Now I realized that
the stack grows 4K by 4K (8K by 8K on 64 bits), which means a lot of
reallocation!

>
> I wonder why the stack in gambas is kind of unlimited.

Why not? :-)

> If you accidently create a program that do infinite recursion, no one
> complains and in a short time the computer's memory has run out.
>
> A better approach (what I personally think) is to set a limit at
> maybe 48 MB or something (which only should actually be reached if
> you do infinite recursion). The normal stack size in a C program is 8
> MB on my computer, and if it gets overflowed, you get segmentation
> fault.

Maybe I should use getrlimit(RLIMIT_STACK, ...) to get the maximum C
stack limit, and use it as the maximum Gambas stack limit too?

> If you mmap the stack with mmap(NULL, 48<<  20,
> PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0), the real
> memory usage will only be what is actually used (only the pages that
> are touched). One extra benifit with that is that the stack doesn't
> have to be relocated ;)

Mmm. I didn't think about using mmap. You should have told me before. 
:-) No relocation anymore, and some code I can throw away. I like that.

I'm waiting for a first shot of your component with some sort of 
tremendous impatience. :-)

-- 
Benoît Minisini




More information about the User mailing list