How to reduce Zero Initialised region.

G

Gordon Burditt

I work on an ARM processor based embedded system. Code is mainly in
C language. The project has a huge source base. We are supposed to
optimise it. Most datastructures are declared as static and which
directly go into the Zero Initialised region. We need to cut the size
of this ZI region by at least 30%.

*ONLY* that region? It's OK and useful to move the arrays from the
Zero Initialized region to the Non-Zero Initialized region?

E.g. change from
char netbuffer[2048];
to
char netbuffer[2048] = {1};
The one way i see of doing this is by removing these static arrays
and passing a pointer to the data structure whenever required. but
since these global arrays are used through out the code. A re-write
seems inevitable!

To meet what you asked for, but what I doubt was intended:

Initialize the arrays to something Non-Zero. Then in an initialization
routine, call memset() on them. This has the dubious advantages of:

- Arrays move from the Zero Initialized region (which just needs to be zeroed
out) to the Non-Zero Initialized region (which needs loading with data from
somewhere).
- The amount of RAM required doesn't get any smaller.
- If code is loaded from disk, it takes longer and the executable is bigger.
- If Non-Zero Initialized data is loaded from ROM, you need more ROM space
for the shadow image of initialized data.
- The code section gets a little bigger for the initialization code.
- The startup time gets a little longer for the initialization code.
two questions I had.
1. Am I right in doing this(passing pointer instead of making the data
structure static) ?

You still have to allocate the array, whether you have a pointer to it
or not. If the array isn't static, what is it? Automatic? Allocated
with malloc()?
2. Is there any alternative to this ?

One way you CAN save memory deals with the required lifetime of
these arrays. If they are all needed simultaneously, your overall
RAM requirement won't go down. If they have separate lifetimes,
you could possibly save a lot with auto (but these take up space,
too!) or malloc() allocation, keeping the array in existence only
while it is needed. But this probably involves a major rewrite of
the code.
 
K

Keith Thompson

Christopher Layne said:
Telling people how to act doesn't do a damn thing - demonstrating usually
yields better results.

Great. Please demonstrate for us how we should act.
 
C

CBFalconer

Christopher said:
It's just more fun for the comp.lang.c pedants to spin their wheels
on. Don't they have anything productive to do?

Serious fear of collapse of everything structured - as if not
replying in a snarky manner to the guy's lack of vowels will result
in everyone doing it tomorrow.

Telling people how to act doesn't do a damn thing - demonstrating
usually yields better results.

Did I really have to put a smiley after:
rgt? red/green/turquoise? rabid grovelling twerp? rapacious
grown teenager? redundant governmental tax? Please spell out
your insults.

I spent some time thinking up translations :)

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
K

Keith Thompson

Christopher Layne said:
Which is somehow worse than telling you how to act? Do you believe that?

Looking back up the thread:

Ajai Jose wrote "rgt" when he meant "right".

CBFalconer pointed it out, and jokingly suggested several things that
"rgt" might expand to. (I read CBFalconer's followup as good-natured
humor, not as harsh criticism, but humor doesn't always come across
well in a plain-text medium.)

Ajai Jose apologized.

Samuel Stearley pointed out that the actual meaning was clear enough.

That should have been the end of it, but you felt the need to jump in
and insult the "comp.lang.c pedants".

You complain about us "telling people how to act" while telling us how
to act. Do you not see the irony?
 
C

Christopher Layne

Keith said:
You complain about us "telling people how to act" while telling us how
to act. Do you not see the irony?

I can definitely see how you would take it that way. My implication was more
along the lines of "is it really that important to create a sub-thread about
every "rgt, plz" etc. issued here? It's happens like clockwork, everytime.
 
T

Thad Smith

Chris said:
Because that's what they're running out of. It's an embedded system:
some of them have Funny Specifications. I /suspect/, given that it's
an ARM, that there's some zero-initialised memory that's directly
addressable from a dedicated register and hence is only 4K wide.
(If you don't have a dedicated register you need to load the
address into a spare register before addressing, which means either
loading a pointer you /can/ directly address, which, since we've
eliminated "directly addressed from a dedicated register", means
"directly addressed via the PC", which means you may have multiple
copies of the constant lying around, bad news for embedded; or you
have to assemble the constant in-line, taking at least one and
maybe more instructions, ditto.) But that's just an off-topic guess.

I have not worked with ARMs, but suspect that equating zero-initialized
memory with a specific addressing mode is either wrong or an indication
of a deficient compiler.

I have added comp.arch.embedded to the list, which probably has someone
that can address your particular system, if you specify the
configuration of processor, memory, and compiler. Followups are also
set to comp.arch.embedded, since the issues here are off-topic for
comp.lang.c.
 
A

Ajai Jose

to act. Do you not see the irony?


Thanks to all the respondents,
I am trying out what Eric Suggested. that is calloc when required and
just keep the pointer global.


Regards,
Ajai Jose.
 
R

Richard

Christopher Layne said:
It's just more fun for the comp.lang.c pedants to spin their wheels on. Don't
they have anything productive to do?

Serious fear of collapse of everything structured - as if not replying in a
snarky manner to the guy's lack of vowels will result in everyone doing it
tomorrow.

Telling people how to act doesn't do a damn thing - demonstrating usually
yields better results.

I have pointed this out numerous times. Teach by example.

But CBF in particular likes to hear the sound of his own voice. I
wouldn't mind but most code excerpts he has posted look and taste like
some beginners home brew anyway.
 
R

Richard

Keith Thompson said:
Looking back up the thread:

Ajai Jose wrote "rgt" when he meant "right".

CBFalconer pointed it out, and jokingly suggested several things that

Not "jokingly". Facetiously. Big difference.
 
R

Richard

Christopher Layne said:
I can definitely see how you would take it that way. My implication was more
along the lines of "is it really that important to create a sub-thread about
every "rgt, plz" etc. issued here? It's happens like clockwork, everytime.

Yup. Little man's disease is a common affliction. Can't wait to correct
people at every opportunity. A shame as there are some seriously good
guys there whose output is clouded by the usual people and their
attempts to out do each other.
 
A

aslam_sheikh1975

Not "jokingly". Facetiously. Big difference.

yeah right!
CBFalconer;s signature speaks a lot about him

<....>
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
<...>

Making an issue out of nothing when the original poster has not
offended anybody at all.
I spent some time thinking up translations :)

Pray keep ur translations to your good self will you ? spare us the
macabre wordings in this Technical Mailing list.

I see a barrage of pedants ranting but when will this useless pedantry
ever stop. (someone in the next cube just said "till CBF kicks the
bucket " )


Aslam
 
C

CBFalconer

.... snip ...

Pray keep ur translations to your good self will you ? spare us
the macabre wordings in this Technical Mailing list.

I rarely translate anything to Ur. In fact, I don't even know that
language. I believe it has not been seriously used for about 3000
years. Back then it was quite important in Mesopotamia. In fact,
I seriously doubt that suitable alphabets exist for Urian in the
present coding standards.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
M

Mark McIntyre

Yup. Little man's disease is a common affliction. Can't wait to correct
people at every opportunity. A shame as there are some seriously good
guys there whose output is clouded by the usual people and their
attempts to out do each other.

Richard, you're rapidly approaching a lot of people's killfiles. I
suggest you consider that you're a newcomer here, showing far from
great expertise in C, and you're treating the regulars with some
considerable contempt. Do you think thats likely to impress anyone?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
J

J. J. Farrell

(e-mail address removed) wrote:

... snip ...


I rarely translate anything to Ur. In fact, I don't even know that
language. I believe it has not been seriously used for about 3000
years. Back then it was quite important in Mesopotamia. In fact,
I seriously doubt that suitable alphabets exist for Urian in the
present coding standards.

Unicode & ISO 10646: U+12000 to U+1236E and U+12400 to U+12473. Needs
wchar_t to be at least 17 bits wide if they're to be handled as C wide
characters.
 
R

Richard Bos

J. J. Farrell said:
Unicode & ISO 10646: U+12000 to U+1236E and U+12400 to U+12473. Needs
wchar_t to be at least 17 bits wide if they're to be handled as C wide
characters.

Hey, that's new! Interesting.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top