From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Ian Pilcher <i.pilcher@comcast.net>
Cc: Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: initialize data not at file scope - WTF?
Date: Mon, 12 Jan 2004 16:54:05 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.53.0401121644190.6412@chaos> (raw)
In-Reply-To: <4003131E.1090408@comcast.net>
On Mon, 12 Jan 2004, Ian Pilcher wrote:
> In include/linux/init.h, it says:
>
> For initialized data:
> You should insert __initdata between the variable name and equal
> sign followed by value, e.g.:
>
> static int init_variable __initdata = 0;
> static char linux_logo[] __initdata = { 0x32, 0x36, ... };
>
> Don't forget to initialize data not at file scope, i.e. within a
> function, as gcc otherwise puts the data into the bss section and not
> into the init section.
>
> Does this mean that __initdata can't be used for file scope variables,
> that it can only be used for file scope variables, or something else?
>
> Thanks!
Data, not at file-scope, means data like this:
int foo()
{
static int bar = 0;
}
Bar is private to function foo(). It does not have file-scope.
However, it is static and therefore is expected to persist over
multiple calls to foo. It, therefore, does not exist on the
stack as local data. Instead, it is normally put in ".bss" or
".data" depending upon initialization.
If you want this data to go away after initialization, you
declare it as:
static int bar __initdata = 0;;
Any data you want to go away after initialization, including
file-scope data, can get the __initdata attribute. FYI, this
puts the data in a special segment that gets freed after
initialization. The idea is to save RAM.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.
prev parent reply other threads:[~2004-01-12 21:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-12 21:35 Ian Pilcher
2004-01-12 21:54 ` Richard B. Johnson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.53.0401121644190.6412@chaos \
--to=root@chaos.analogic.com \
--cc=i.pilcher@comcast.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®