[Gambas-user] Gambas has Gosub now!

Emil Lenngren emil.lenngren at ...626...
Tue Mar 6 02:11:06 CET 2012


Yeah, if there is no stack relocation, I can assume that a lot of pointers
into the stack will not change during other external calls, which should
make code more optimized.

Since local variables and stack frames in gambas take up more space than
they do in C, I think the stack should be bit bigger than the default in C
(compiled with gcc).

/Emil

2012/3/6 Benoît Minisini <gambas at ...1...>

> 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
>
>
> ------------------------------------------------------------------------------
> Keep Your Developer Skills Current with LearnDevNow!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-d2d
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list