Data Alignment.

Discussion in 'C++' started by vineet, Sep 22, 2008.

  1. vineet

    vineet Guest

    Hi,
    To make data aligned to memory boundry, compiler pedded some byte. I
    wanted to know if these bytes are initialized? or compiler pedded some
    un initialized byte.

    Thanks,
     
    vineet, Sep 22, 2008
    #1
    1. Advertising

  2. vineet

    Salt_Peter Guest

    On Sep 22, 11:02 am, vineet <> wrote:
    > Hi,
    > To make data aligned to memory boundry, compiler pedded some byte. I
    > wanted to know if these bytes are initialized? or compiler pedded some
    > un initialized byte.
    >
    > Thanks,


    The padding, if any, is not initialized.
    In fact neither is the data unless you have done so.
    The question is: why would that matter?
    Your code should be completely transparent to padding, regardless of
    platform.
     
    Salt_Peter, Sep 22, 2008
    #2
    1. Advertising

  3. vineet

    Guest

    On Sep 22, 4:02 pm, vineet <> wrote:
    > Hi,
    > To make data aligned to memory boundry, compiler pedded some byte. I
    > wanted to know if these bytes are initialized? or compiler pedded some
    > un initialized byte.
    >
    > Thanks,


    I think it is depends upon which part of the memory data sits - stack,
    heap, initialized DS, Uninitialized DS


    - nOby jOse
     
    , Sep 22, 2008
    #3
  4. vineet

    Fei Liu Guest

    wrote:
    > On Sep 22, 4:02 pm, vineet <> wrote:
    >> Hi,
    >> To make data aligned to memory boundry, compiler pedded some byte. I
    >> wanted to know if these bytes are initialized? or compiler pedded some
    >> un initialized byte.
    >>
    >> Thanks,

    >
    > I think it is depends upon which part of the memory data sits - stack,
    > heap, initialized DS, Uninitialized DS
    >
    >
    > - nOby jOse

    Also some compilers (e.g. intel) has compiler flags such as
    '-no-bss-init' to allow finer control of memory initialization. Really,
    the answer is platform-compiler dependent and has not much to do with C++.
     
    Fei Liu, Sep 22, 2008
    #4
  5. On Sep 22, 4:37 pm, Salt_Peter <> wrote:
    > On Sep 22, 11:02 am, vineet <> wrote:
    >
    > > Hi,
    > > To make data aligned to memory boundry, compiler pedded some byte. I
    > > wanted to know if these bytes are initialized? or compiler pedded some
    > > un initialized byte.

    >
    > > Thanks,

    >
    > The padding, if any, is not initialized.
    > In fact neither is the data unless you have done so.


    Unless it is POD with static storage duration, in which case it is
    guaranteed to be zero-initialised.

    --
    Max
     
    Maxim Yegorushkin, Sep 23, 2008
    #5
  6. vineet

    James Kanze Guest

    On Sep 23, 11:00 am, Maxim Yegorushkin <>
    wrote:
    > On Sep 22, 4:37 pm, Salt_Peter <> wrote:


    > > On Sep 22, 11:02 am, vineet <> wrote:


    > > > To make data aligned to memory boundry, compiler pedded
    > > > some byte. I wanted to know if these bytes are
    > > > initialized? or compiler pedded some un initialized byte.


    > > The padding, if any, is not initialized.
    > > In fact neither is the data unless you have done so.


    > Unless it is POD with static storage duration, in which case
    > it is guaranteed to be zero-initialised.


    The members, for types where zero initialization makes sense
    (not references, for example). And this is guaranteed to occur
    even within types with constructors, etc.; zero initialization
    takes place before any dynamic initialization. But the original
    question concerned padding, and that's not guaranteed (for the
    obvious reason that what is meant by zero initialization depends
    on the type, and padding has no type).

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 23, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?RagnarDanneskj=F6ld?=

    Data Alignment Macros?

    =?ISO-8859-1?Q?RagnarDanneskj=F6ld?=, Feb 16, 2004, in forum: C Programming
    Replies:
    2
    Views:
    413
    Peter Pichler
    Feb 20, 2004
  2. pt
    Replies:
    4
    Views:
    353
    Hallvard B Furuseth
    Aug 1, 2006
  3. pt
    Replies:
    5
    Views:
    403
    Hallvard B Furuseth
    Aug 1, 2006
  4. Charlie84

    Data alignment

    Charlie84, Dec 18, 2008, in forum: VHDL
    Replies:
    6
    Views:
    890
    Charlie84
    Dec 21, 2008
  5. Eric Sosman

    Re: Data alignment and endianess

    Eric Sosman, Jan 23, 2011, in forum: C Programming
    Replies:
    32
    Views:
    876
    BartC
    Feb 3, 2011
Loading...

Share This Page