Re: char*



On 27 Sep, 13:45, "Joachim Schmitz" <nospam.j...@xxxxxxxxxxxxxxxxxx>
wrote:
"RedLars" <Liverpool1...@xxxxxxxxx> schrieb im Newsbeitragnews:1190893329.341315.175760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



On 27 Sep, 10:04, "Joachim Schmitz" <nospam.j...@xxxxxxxxxxxxxxxxxx>
wrote:
"RedLars" <Liverpool1...@xxxxxxxxx> schrieb im
Newsbeitragnews:1190877122.177714.313450@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Thanks for the reply

On 27 Sep, 08:34, r...@xxxxxxxxxxxxxxxxxxxxxx (Richard Bos) wrote:
RedLars <Liverpool1...@xxxxxxxxx> wrote:
This defines a local variable placed on the stack which will be
cleaned up when it goes out of scope, right?

You don't know that. All you know is that it _can_ be cleaned up when
it
goes out of scope, not that it is.

Given the method below, say for some strange reason this was called
every minute within an application, would this cause a memory leak?
void foo()
{
int x = 2;
char y[] = "hello world";
char * z = "Bye bye";
}

No, it won't leak memory

Wouldn't running foo() multiple time create multipe string literal
"Bye bye" that are in fact not reference by any code, hence not used.

No. Only once.

So the literal is of no use once the method is finsihed yet continue
to exist. So running foo() 1000 time would create 1000 string literal
in memory.

No, only once...

So the second time foo() is called the string literal constructed
during the first iteration is re-used? How are string literal stored
and how is this managed? I mean, does the runtime library loop through
some static string literal array when it sees:
const char * x = <text>
to see if it can find <text> already defined?

Thanks for the help.


.



Relevant Pages

  • Re: Syntax simplification
    ... >>IMO, the type/behaviour polymorphism of has always ... and that of empty words and empty sentences. ... 'foo bar'", or "take the first word of the sentence 'foo bar'". ... >reason for dynamic scope -- the user should not have to know that there is ...
    (comp.lang.logo)
  • Re: Trouble with variable scoping
    ... You are confusing file scope with global. ... That is possibly the most common misperception about Perl that I've ... fully-qualify any global variables you decide to use. ... a lexical variable $foo exists in the current scope. ...
    (perl.beginners)
  • Re: Switching From YUICompressor to Closure Compiler Using ANT
    ... if (foo) foo.bar; ... to anyone understanding the difference between function expressions and function declarations. ... One just needs to know ECMAScript syntax and what could be changed into something shorter without changing program behavior. ... a called function can be inlined where it shares scope. ...
    (comp.lang.javascript)
  • Re: Confusion about Image object and PictureBox usage.
    ... I am not sure if I have a memory leak or not. ... >> scope, as with almost all objects in .NET. ... >> leak is coming from elsewhere, possibly in the code that is converting ... >> JPEG getting converted to a .NET bitmap? ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Signal handlers, objects and reference counting.
    ... "local", then it would automatically destroy the sub-ref, which would then ... lexical scope and the SIG localization goes out of dynamic scope. ... package foo; ... Does each circularity lie entirely within one module, ...
    (comp.lang.perl.misc)