Re: char*
- From: RedLars <Liverpool1892@xxxxxxxxx>
- Date: Thu, 27 Sep 2007 05:14:24 -0700
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.
.
- Follow-Ups:
- Re: char*
- From: Richard Bos
- Re: char*
- References:
- Prev by Date: Re: switch on strings
- Next by Date: Re: what does this warning mean ?
- Previous by thread: Re: char*
- Next by thread: Re: char*
- Index(es):
Relevant Pages
|