lkml.org 
[lkml]   [2009]   [Dec]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] NTFS: Change string pointers to string constants.


Marcin Slusarz schrieb:
> On Mon, Dec 07, 2009 at 05:47:13PM -0800, Joe Perches wrote:
>> On Tue, 2009-12-08 at 00:57 +0000, Anton Altaparmakov wrote:
>>> Can you please explain the rational for making this change?
>> Perhaps it's not worth much, but it saves a pointer reference.
>>
>> $ cat pointer.c
>> #include <string.h>
>> #include <stdio.h>
>>
>> int main (int argc, char** argv)
>> {
>> static const char *foo = "abcdefg";
>> printf("%s\n", foo);
>> return 0;
>> }
>>
>> $ gcc -c pointer.c
>> $ size pointer.o
>> text data bss dec hex filename
>> 37 4 0 41 29 pointer.o
>>
>> $ cat reference.c
>> #include <string.h>
>> #include <stdio.h>
>>
>> int main (int argc, char** argv)
>> {
>> static const char foo[] = "abcdefg";
>> printf("%s\n", foo);
>> return 0;
>> }
>>
>> $ gcc -c reference.c
>> $ size reference.o
>> text data bss dec hex filename
>> 36 0 0 36 24 reference.o
>
> Yeah, for static variables it's better. But for automatic variables
> it's worse, because it now has to do a copy at runtime.
> And the patch changes both types.
>
> $ size pointer.o reference.o
> text data bss dec hex filename
> 101 8 0 109 6d pointer.o
> 96 0 0 96 60 reference.o
>
> $ size pointer-nonstatic.o reference-nonstatic.o
> text data bss dec hex filename
> 106 0 0 106 6a pointer-nonstatic.o
> 109 0 0 109 6d reference-nonstatic.o
> --


nobody should spend to much time on this. gcc <what ever next version>
will have different results. It is better to spend time improving
the compiler and make it generate shorter/faster code.

just my 2 cents,
wh


\
 
 \ /
  Last update: 2009-12-09 16:11    [W:0.552 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site