Re: How to reduce Zero Initialised region.



On 31 Jan 2007 01:50:25 -0800, "Ajai Jose" <ajai.jose@xxxxxxxxx> wrote
in comp.lang.c:

Hi ,
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%.
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!

two questions I had.
1. Am I right in doing this(passing pointer instead of making the data
structure static) ?

If you pass a pointer to the data structure, the structure itself
still has to exist somewhere. If the values in the structure need to
persist for some time, in between function calls, they probably need
to have static storage duration anyway.

2. Is there any alternative to this ?


Thanks in Advance,
Ajai.

The issue is not so much whether a function accesses a data structure
by a name with external linkage, but rather how long the structure
must exist.

If you have 100 structures and each of them must retain its data from
the time it is initialized for as long as the program runs, then they
pretty much need to have static storage duration.

On the other hand, if your program needs 50 structures when doing one
type of operation, and a different set of 50 structures when doing
another operation, and in both cases does not need the data anymore
once the operation is finished, you can allocate them automatically in
a function or dynamically, and not have them all taking up memory all
the time.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: using virtual function in c
    ... Here, the machine will convert &ii (a word pointer) to a byte pointer, ... If there is only one "virtual function" for a given data structure, ...
    (comp.lang.c)
  • Re: Why C for operating systems
    ... I have seen far too many hard-to-debug operating system bugs due to ... It would be far better if C pointer ... to be something related to the data structure. ... language functions to do specific jobs such as turning the address ...
    (comp.programming)
  • Re: Using sparse to catch invalid RCU dereferences?
    ... So the address_space attribute says what the pointer points to rather ... Probably because I am not the greatest gcc expert around... ... Then we would know that when tree lock is held the data structure is ... section with respect to another RCU-protected data structure. ...
    (Linux-Kernel)
  • Marshaling
    ... Actually it returns pointer to it. ... a pointer to a pointer to a copy of the data structure. ... According to this the date returned from WTSEnumerateSessions function is a ... DWORD Reserved, ...
    (microsoft.public.dotnet.languages.vb)
  • Marshaling
    ... Actually it returns pointer to it. ... a pointer to a pointer to a copy of the data structure. ... According to this the date returned from WTSEnumerateSessions function is a ... DWORD Reserved, ...
    (microsoft.public.dotnet.framework)