[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH] top: fix parsing of /proc/meminfo
From: Rich Felker <dalias () libc ! org>
Date: 2014-07-22 17:30:42
Message-ID: 20140722173042.GY17402 () brightrain ! aerifal ! cx
[Download RAW message or body]
On Tue, Jul 22, 2014 at 08:24:30PM +0300, Timo Teras wrote:
> On Tue, 22 Jul 2014 13:07:15 -0400
> "Cathey, Jim" <jcathey@ciena.com> wrote:
>
> > >Am I missing something here? There is no structure, just a
> > >character pointer. If you leave off "static" it will be compiled as
> > >an instruction that pushes a constant onto the stack, by any/every
> > >compiler.
> >
> > Which is probably _larger_ code than just referring to something
> > stored in the .text/.data segment. It's copying something that is
> > found in text/data into the stack space, then referring to that
> > address thereafter. The compiler has to do:
> >
> > Copy A->B
> > Then use &B.
> >
> > -vs-
> >
> > Use &A.
> >
> > You do this when you want the ability to modify B.
> > If A is fixed and inviolate, you mark it static const
> > and be done with it. What this turns into, exactly,
> > depends upon your compiler, CPU, and ABI, but I can't
> > think of any case where the extra copy is going to
> > turn out _better_ than the simpler case.
>
> Usage of 'static' depends whether it's "const char *" or "const
> char[]". When defining "const char *" static does not make sense, as
> in theory it should enforce *also* the pointer value to go to .rodata
> (the string literal of course goes there too). So you might end up
> wasting one extra pointer in .rodata.
>
> OTOH, with "const char[]" you definitely want the "static" as other
> wise you'd end up with the copy described above.
>
> I only suggested removing 'static' since I had it a pointer. The latest
> patch has array, and thus is static.
I agree that using a static const array is the best approach here, and
that with a *single* pointer, making a static object to hold the
pointer rather than just an automatic const-qualified variable is a
pessimization, if anything. However static const pointers are useful
when they're arrays of pointers, or part of structures, etc., but
their usefulness is limited except with static linking and non-PIE
main programs, since they'll need relocations for PIC/PIE which would
throw them out of rodata.
Rich
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic