<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Jarrett Billingsley schrieb:
<blockquote cite="mid:fggbjm$mld$1@digitalmars.com" type="cite">
<pre wrap="">"Xinok" <a class="moz-txt-link-rfc2396E" href="mailto:xnknet@gmail.com"><xnknet@gmail.com></a> wrote in message
<a class="moz-txt-link-freetext" href="news:fgg9q8$jlr$1@digitalmars.com">news:fgg9q8$jlr$1@digitalmars.com</a>...
</pre>
<blockquote type="cite">
<pre wrap="">It seems that variables that are used by a nested function are allocated
on the heap rather than the stack. This was my test code:
void delegate() foo(){
int v = 60;
int c = 35;
writefln(&c);
writefln(&v);
return {writefln(&v);};
}
void main(){
void delegate() one = foo();
one();
}
Prints:
12FF18
8B2FF4
8B2FF4
The address of 'v' doesn't change. What you do notice is the great
difference of the memory addresses between int v and int c, which suggests
that 'v' is allocated on the heap rather than the stack.
</pre>
</blockquote>
<pre wrap=""><!---->
Hm. Don't have a D2 compiler with me -- could you run the following and
tell me what it prints?
void main()
{
int v, c;
void foo()
{
writefln(&c);
}
writefln(&v);
writefln(&c);
}
I'm wondering if the compiler is smart enough not to allocate variables on
the heap if it doesn't have to. (I'm not returning foo.)
</pre>
</blockquote>
<br>
Prints:<br>
13FF28<br>
13FF2C<br>
<br>
...whatever that means...<br>
<br>
<br>
~Extrawurst<br>
</body>
</html>