Data Alignment.

V

vineet

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,
 
S

Salt_Peter

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.
 
N

nobyjos

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
 
F

Fei Liu

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++.
 
M

Maxim Yegorushkin

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.
 
J

James Kanze

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).
 

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

Similar Threads

Grid text alignment 1
alignment issues 8
Alignment problems 20
std::vector padding behavior and alignment 7
Help with pointers 1
Alignment 17
Alignment guarantees? 6
Controlling buffer alignment in file.read() 4

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top