Is it's correct to say that ALL types that can grow are place on heap?

Timoses timosesu at
Tue Sep 11 10:11:50 UTC 2018

On Saturday, 8 September 2018 at 22:51:17 UTC, Ali Çehreli wrote:
> On 09/08/2018 02:19 AM, Suliman wrote:
> > Is it's correct to say that ALL types that can grow are place
> on heap
> > and types that not growing (int, char, pointer) are place on
> stack?
> The question is not that simple. :)
> First, there is also the area used for objects that are static 
> and object that are defined at module scope. That is different 
> from both the call stack and the heap. Let's ignore them...
> There are automatic objects like local variables inside a 
> function and function parameters. They normally live on the 
> stack. (However, the compiler may pass some parameters in CPU 
> registers without allocating any memory at all.)

Is this why it is said that passing parameters by value can be 
more efficient?
Cause for a ref parameter it would require passing the address 
which would require to be allocated?

Aww, I really would love some insights into function parameter 
passing. Why is it said that passing by value can be more 
efficient at times?
Since it is also said that passing large structs by value can be 
expensive, why then would it not be cheaper to ALWAYS pass 
everything by reference? What mechanism is behind the scene that 
follows one to reason that sometimes passing by value is less 

I get that passing an int by reference would cause indirections 
which need to be resolved whereas passing the int by value is 
just one copy (I guess).

This topic kinda seemed fit for my question that I was carrying 
around for some time.

More information about the Digitalmars-d-learn mailing list