Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #11308

Re: Stack is slow than heap?

From Edek <edek.pienkowski@gmail.com>
Newsgroups comp.lang.c++
Subject Re: Stack is slow than heap?
Date 2011-11-07 20:10 +0100
Organization ATMAN - ATM S.A.
Message-ID <j99abo$3fo$1@node2.news.atman.pl> (permalink)
References <3b85a1bb-7531-4d9c-9c18-77e93a5d52b7@r7g2000vbg.googlegroups.com> <4eb82371$0$1391$4fafbaef@reader1.news.tin.it> <4eb827aa$0$1383$4fafbaef@reader2.news.tin.it>

Show all headers | View raw


On 11/07/2011 07:50 PM, io_x wrote:
> "io_x"<a@b.c.invalid>  ha scritto nel messaggio
> news:4eb82371$0$1391$4fafbaef@reader1.news.tin.it...
>> #if you call 100 function as
>> #for(i=0; i<100; ++i) func(x);
>> #the stack grow as it is only one func() call.
>> #the stack grow to number of function call
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> #only if the function is recursive i.e. call itself
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> the above is false
> for example if
> int  f0(int x){return  x-1;}
> int  f1(int x){return f0(x);}
> int  f2(int x){return f1(x);}
>
> f2(3)
> make grow the stack to number of function call
> even if f2() is not recursive
>
> but it is difficult to find such way to dispose
> functions...

Two ways: inlining, that's one, but it might be limited in
depth, VC had some flags saying how many recursive calls to
inline.

Also C/C++ compilers do something called tail-call.
Tail-call replaces return-what-call-returns with
a jump (a machine goto). Obviously, there must be another return
somewhere eventually or an exception and this return
replaces the return-call->return; it is one of the
reasons why debugging optimised code or getting the
exception stack might not be very productive in C++.

In this way recursive algorithms can become iterative
or mixed in execution though.

Edek

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Stack is slow than heap? Nephi Immortal <immortalnephi@gmail.com> - 2011-11-07 08:27 -0800
  Re: Stack is slow than heap? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-11-07 11:47 -0500
    Re: Stack is slow than heap? BGB <cr88192@hotmail.com> - 2011-11-07 15:28 -0700
      Re: Stack is slow than heap? Nephi Immortal <immortalnephi@gmail.com> - 2011-11-08 07:35 -0800
        Re: Stack is slow than heap? "io_x" <a@b.c.invalid> - 2011-11-08 18:17 +0100
          Re: Stack is slow than heap? Nephi Immortal <immortalnephi@gmail.com> - 2011-11-08 11:39 -0800
            Re: Stack is slow than heap? "io_x" <a@b.c.invalid> - 2011-11-09 03:42 +0100
              Re: Stack is slow than heap? "io_x" <a@b.c.invalid> - 2011-11-09 03:55 +0100
                Re: Stack is slow than heap? "io_x" <a@b.c.invalid> - 2011-11-09 03:58 +0100
      Re: Stack is slow than heap? Cholo Lennon <chololennon@hotmail.com> - 2011-11-08 17:52 -0300
        Re: Stack is slow than heap? BGB <cr88192@hotmail.com> - 2011-11-09 00:09 -0700
          Re: Stack is slow than heap? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-09 17:33 +0000
            Re: Stack is slow than heap? Juha Nieminen <nospam@thanks.invalid> - 2011-11-10 06:44 +0000
              Re: Stack is slow than heap? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-10 20:14 +0000
                Re: Stack is slow than heap? Juha Nieminen <nospam@thanks.invalid> - 2011-11-10 21:01 +0000
                Re: Stack is slow than heap? Cholo Lennon <chololennon@hotmail.com> - 2011-11-10 18:55 -0300
                Re: Stack is slow than heap? Juha Nieminen <nospam@thanks.invalid> - 2011-11-11 07:37 +0000
                Re: Stack is slow than heap? gwowen <gwowen@gmail.com> - 2011-11-11 02:18 -0800
                Re: Stack is slow than heap? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-11-10 22:34 +0000
          Re: Stack is slow than heap? Paavo Helde <myfirstname@osa.pri.ee> - 2011-11-09 14:38 -0600
            Re: Stack is slow than heap? BGB <cr88192@hotmail.com> - 2011-11-09 15:30 -0700
  Re: Stack is slow than heap? "io_x" <a@b.c.invalid> - 2011-11-07 19:32 +0100
    Re: Stack is slow than heap? "io_x" <a@b.c.invalid> - 2011-11-07 19:50 +0100
      Re: Stack is slow than heap? Edek <edek.pienkowski@gmail.com> - 2011-11-07 20:10 +0100
  Re: Stack is slow than heap? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-11-08 03:00 -0800
    Re: Stack is slow than heap? Nephi Immortal <immortalnephi@gmail.com> - 2011-11-08 07:45 -0800
      Re: Stack is slow than heap? "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2011-11-08 17:28 +0100
      Re: Stack is slow than heap? Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-11-09 02:20 -0800
        Re: Stack is slow than heap? Werner <werasm@gmail.com> - 2011-11-09 03:03 -0800
          Re: Stack is slow than heap? Dombo <dombo@disposable.invalid> - 2011-11-09 20:16 +0100
            Re: Stack is slow than heap? Richard Damon <news.x.richarddamon@xoxy.net> - 2011-11-09 23:35 -0500

csiph-web