<div dir="ltr">Thanks for your response, this clears up things alot for me...<br><div><div class="gmail_extra"><br><div class="gmail_quote">On 30 March 2015 at 23:46, Alpar Juttner <span dir="ltr"><<a href="mailto:alpar@cs.elte.hu" target="_blank">alpar@cs.elte.hu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<span class=""><br>
>     lemon::ListDigraph dg1;<br>
>     lemon::ListDigraph::Node n1 = dg1.addNode ( );<br>
>     lemon::ListDigraph* dg2 ( new lemon::ListDigraph );<br>
>     lemon::ListDigraph::Node n2 = dg2->addNode ( );<br>
</span>>  [...]<br>
<span class="">> Where are n1 and n2, respectively allocated (stack and heap?)...<br>
<br>
</span>(Assuming this code is inside a function block) They are both normal<br>
local variables, therefore they are allocated on the stack.<br>
In fact, they are simple classes containing nothing else but a single<br>
integer (the id of the node it referres to).<br>
Therefore --- when compiler optimization is on -- the chances are that<br>
the whole allocation will be optimized out and they will be stored<br>
directly in a CPU register.<br>
<span class=""><br>
>  and what are they, pointers, references or objects?<br>
<br>
</span>Objects (classes), see above.<br>
<span class=""><br>
>  Somewhere in the user-list-archives there's a post asking about<br>
> constructing large graphs, with an advice to use the heap (case 2) and<br>
> std::vector for (automatic) memory management...<br>
<br>
</span>It's probably a misunderstaning. This comment - I guess - was referring<br>
to the use case when you need to allocate a large number of graphs. The<br>
size of the graph does not matter, because the actual contents of the<br>
graph will always be stored in the heap, even is the graph was allocated<br>
on the stack (as a local variable). This is analogous to std::vector<><br>
and similar containers.<br></blockquote><div><br></div><div>This is the info that I was seeking... and worrying about (...because the actual contents of the<br>
graph will always be stored in the heap...)! So with a couple of graphs, the stack is perfectly fine .-).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class=""><br>
>  When using dg2, does everything that is attached to it (f.e. NodeMap)<br>
> end up on the heap?<br>
<br>
</span>Yes, but same happens in case of dg1, too.<br>
<span class=""><br>
> When doing:<br>
>     lemon::ListDigraph::Node n1 = n2;<br>
> has anything happened to either graph?<br>
<br>
</span>No, nothing.<br>
Nodes are created only when you call addNode().<br>
n1 and n2 are not the node itself, but a kind of reference to it. Each<br>
graph-node has an ID, and type lemon::ListDigraph::Node just stores this<br>
ID.<br></blockquote><div><br></div><div>I reckoned so much, but the documentation is totally silent about it...<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class=""><br>
>  Is n1 now a copy of n2, or is it now n2?<br>
<br>
</span>See above.<br>
<span class=""><br>
> Sorry for my ignorance. Thanks in advance for any enlightenment<br>
> offered!<br>
<br>
</span>Don't worry, this mailing-list is for asking questions. I hope I was<br>
able to help.<br></blockquote><div><br></div><div>This absolutely solved my questions... the message I get is: "Get on with it, it's all properly done behind the scenes..." Thanks again... for this great library...<br></div><div> </div></div>Have a good day,<br><br></div><div class="gmail_extra">Degski<br></div></div></div>