[PATCH] top: fix parsing of /proc/meminfo
Michael Conrad
mconrad at intellitree.com
Tue Jul 22 15:21:32 UTC 2014
On 07/21/2014 04:44 PM, Dan Fandrich wrote:
> On Sun, Jul 20, 2014 at 11:20:13AM +0300, Timo Teras wrote:
>> On Sat, 19 Jul 2014 21:31:33 +0200
>> Dan Fandrich <dan at coneharvesters.com> wrote:
>>
>>> On Fri, Jul 18, 2014 at 10:07:06PM +0300, Timo Teräs wrote:
>>>> and do it in smaller code:
>>>>
>>>> diff --git a/procps/top.c b/procps/top.c
>>>> index 530f45f..e60dab6 100644
>>>> --- a/procps/top.c
>>>> +++ b/procps/top.c
>>>> @@ -501,10 +501,27 @@ static void display_cpus(int scr_width, char
>>>> *scrbuf, int *lines_rem_p)
>>>> static unsigned long display_header(int scr_width, int
>>>> *lines_rem_p) {
>>>> + static const char *fields =
>>> Minor suggestion: this should be
>>> static const char * const fields =
>>>
>>> so it can go into .rodata.
>>
>> That said, adding the second "const" does make sense. And thinking more,
>> "static" should probably be left out.
> static needs to be left in in order to avoid a copy of the structure onto the
> stack at run-time.
>
> All this may be moot with an optimizing compiler, but not all compilers are
> necessarily smart enough to do this on their own. Adding those keywords also
> makes it more clear what the intent is of the structure.
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.
More information about the busybox
mailing list