 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Quentin Yuan Guest
|
Posted: Thu May 17, 2007 9:11 am Post subject: Is how to lay out the constant string compiler dependent? |
|
|
I always consider that the constant character strings of which
literal value are the same lay out at the same logic address, in
another words, every constant character string have only one copy in
the program. My view base on that if it doesn't that, you lose the
memory of the string that you have used except store the address in a
pointer, this is a form of memory leak although it doesn't really eat
the memory as the general memory leak. The x86 machine always support
my view:-)
But recently someone told me that the addresses of the same character
strings are not the same in SunOS, so it seems that how to lay out the
constant strings is complier dependent. If it's true, I wonder the
reason why my view is wrong? Both informations and links are
appreciated. Thanks to all!
Best Regards |
|
| Back to top |
|
 |
Chris Dollin Guest
|
Posted: Thu May 17, 2007 9:11 am Post subject: Re: Is how to lay out the constant string compiler dependent |
|
|
Quentin Yuan wrote:
| Quote: | I always consider that the constant character strings of which
literal value are the same lay out at the same logic address, in
another words, every constant character string have only one copy in
the program. My view base on that if it doesn't that, you lose the
memory of the string that you have used except store the address in a
pointer, this is a form of memory leak although it doesn't really eat
the memory as the general memory leak. The x86 machine always support
my view:-)
But recently someone told me that the addresses of the same character
strings are not the same in SunOS, so it seems that how to lay out the
constant strings is complier dependent. If it's true, I wonder the
reason why my view is wrong? Both informations and links are
appreciated. Thanks to all!
|
A C implementation is allowed, but not required, to collapse identical
string literals (and parts thereof).
While it's /nice/ to be able to save space this way, it does require
a certain amount of sophistication in the implementation -- the linker
(or its equivalent) must be able to identify the equal areas /and know
that it can collapse them/. Some linkers don't have the language to be
told that.
It would not surprise me if an implementation shared literals in the
same compilation unit even if it couldn't do so across units.
--
"Possibly you're not recalling some of his previous plans." Zoe, /Firefly/
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|