Greg Ercolano wrote:
> Domingo Alvarez Duarte wrote:
>> I thought like you before know that the compiler actually only allocate
>> one copy for any repeated constant string, and remember sizeof() isn't a
>> function it's a compile time calculation, so there is no double memory
>> consumption !
>>
>> You can test it by yourself with something like this:
>>
>> #include<stdio.h>
>>
>> const char *str1() {return "unique";}
>> const char *str2() {return "unique";}
>> const char *str3() {return "unique";}
>>
>> int main()
>> {
>>       printf("%p = %p = %p\n", str1(), str2(), str3());
>>       return 0;
>> }
>>
>> output on my machine: 00403000 = 00403000 = 00403000
>
>       It depends on the compiler.
>
>       g++ behaves as above, but for instance with Microsoft VS 7 I get:
>
> Z:\tmp>cl /TP foo.cxx
> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.00.9466 for 80x86
> Copyright (C) Microsoft Corporation 1984-2001. All rights reserved.
>
> foo.cxx
> Microsoft (R) Incremental Linker Version 7.00.9955
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
> /out:foo.exe
> foo.obj
>
> Z:\tmp>.\foo.exe
> 00408040 = 00408048 = 00408050
>        ^^         ^^         ^^
I didn't tried it but anyway the sizeof() will be replaced at compile 
time by it's size and no double constant string will appear.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to