Properties inherited during fork()

What are the properties inherited by a child process during fork()?
Answer:

Properties inherited:
* open file descriptors
* real uid, real gid, effective uid, effective group id
* process gid
* controlling terminal
* set-user-ID flag and set-group-ID flag
* current working directory
* root dir
* file mode creation mask
* signal mask
* Environment

Differences:
* alarms.
* pending signals.

( selected from Steven Richards, p.192 )

Memory Layout of a Program in UNIX

Memory layout of a Program in a UNIX-environment:



Reference : "The Environment of a Unix Process" in Advanced Programming in the UNIX Environment Richard Stevens, p.168


(High address)
+-------------------+
| | cmd line args and env vars
| |
+-------------------+
| stack |
+-------------------+
| ↓ |
| |
| ↑ |
+-------------------+
| heap |
+-------------------+
|Uninitialized data | init to zero by exec
| (bss) |
+-------------------+ _
| initialized data | |
+-------------------+ |--read from program file by exec
| text | |
+-------------------+ _|
(Low address)

YUV, YCbCr, YPbPr

Differences between YUV, YCbCr and YPbPr:

YUV is a basic color model used in analog color TV broadcasting, YCbCr is a scaled and offset version of the YUV color space, used in digital video applications.(Reference:Video Demysitified, p.19)

Component Video is known as YPbPr. YPbPr is the analog version of YCbCr digital video. (YCbCr is often called YPbPr when used for analog component video)

The YUV color space is used by the PAL (Phase Alternation Line), NTSC (National Television System Committee), and SECAM (Sequentiel Couleur Avec Mémoire or Sequential Color with Memory) composite color video standards. The black-and-white system used only luma (Y) information; color information (U and V) was added in such a way that a black-and-white receiver would still display a normal black-and-white picture.(Reference:Keith Jack(2007) Video Demysitified, 4th Ed p.17)

The YCbCr color space was developed as part of ITU-R BT.601 during the development of a world-wide digital component video standard (discussed in Chapter 4). YCbCr is a scaled and offset version of the YUV color space. Y is defined to have a nominal 8-bit range of 16–235; Cb and Cr are defined to have a nominal range of 16–240. There are several YCbCr sampling formats, such as 4:4:4, 4:2:2, 4:1:1, and 4:2:0.(Reference:Keith Jack(2007) Video Demysitified, 4th Ed p.19)

The various subsampling formats can be pictorially described as follows:
Source:Borivoje Furht Encyclopedia of multimedia p.875
The YCbCr 4:4:4 format has four Cb and four Cr pixels for every 2x2
block of Y pixels, the YCbCr 4:2:2 format has two Cb and two Cr pixels for every 2x2
block of Y pixels, and the YCbCr 4:2:0 format has one Cb and one Cr pixels for every 2x2
block of Y pixels. All the three formats have the Y component at the full picture
resolution. The difference in the formats is that the YCbCr 4:2:2 and YCbCr 4:2:0 formats
have the chroma components at a reduced resolution. The human eye cannot perceive
the difference when chroma is sub sampled. In fact, even the YCbCr 4:2:0 format with
chroma V4 of the luma resolution is sufficient to please the human eye. The YCbCr 4:2:0
format is the predominantly used format and is used in applications such as DVD, digital
TVs, and HDTVs. The YCbCr 4:2:2 is typically used for studio quality applications and
YCbCr 4:4:4 is hardly used. The use of YCbCr 4:2:0 instead of the RGB color space
represents a 50% reduction in image size and is a direct result of exploiting the
perceptual redundancies of the human visual system.( quoted from: Borivoje Furht Encyclopedia of multimedia p.875)



Source: David J. Katz, Rick Gentile Embedded media processing , p.200





Packed and Planar Formats:

YUV formats fall into two distinct groups, the packed formats where Y, U (Cb) and V (Cr) samples are packed together into macropixels which are stored in a single array, and the planar formats where each component is stored as a separate array, the final image being a fusing of the three separate planes. (Ref: fourcc.org )

Subsampling intervals in the horizontal and vertical directions may merit some explanation. The horizontal subsampling interval describes how frequently across a line a sample of that component is taken while the vertical interval describes on which lines samples are taken. For example, UYVY format has a horizontal subsampling period of 2 for both the U and V components indicating that U and V samples are taken for every second pixel across a line. Their vertical subsampling period is 1 indicating that U and V samples are taken on each line of the image. (Ref: fourcc.org )

See also: Discussion of YUV subsampling in The image processing handbook p.36

Multiple inheritance and virutal functions

How is the size of an object affected during multiple inheritance involving virtual functions?

Answer:
For each inheritance hierarchy involving virtual functions, the size increases by the size of ptr to vtable ( 4 bytes ).

For ex:

#include
class A
{
public:
virtual void f() { printf( "%p %s \n", this, __func__ ); }
};
class B
{
public:
virtual void g() { printf( "%p %s \n", this, __func__ ); }
virtual void h() { printf( "%p %s \n", this, __func__ ); }
};

class C: public A, public B
{
void g() { B::g(); }
};
class D: public A
{
};

int main()
{
A* pa;
B* pb;
C c;
pb = &c;
pa = &c;
pb->g();
pa->f();
printf(" A %p , B %p, C %p \n", pa, pb, &c );
return printf(" A %d B %d C %d D %d \n",
sizeof(A),sizeof(B),sizeof(C),sizeof(D)
);
}


Gives the following output:

0xbfe81c58 g
0xbfe81c54 f
A 0xbfe81c54 , B 0xbfe81c58, C 0xbfe81c54
A 4 B 4 C 8 D 4


Here the size of C is printed as 8, because it get two vtable ptrs from A and B.
Also interesting to note that the "this" pointer values are different.
The Memory layout will look something like this:


+-----------+
| vptr----|-------->+-------------+
| A part | | &A::f | 0 | ( A & C's vtbl )
+-----------+ +-------------+
| vptr----|-------->+---------------------+
| B part | | &C::g | -delta(B) | ( B's vtbl:)
| | | &B::h | 0 |
+-----------+ +---------------------+
| C Part |
| |
+-----------+


During multiple inheritance, the vtbl also contains the detla adjustments for this pointer.

Sometimes, instead of delta, it contains the pointer to code which adjusts the this pointer the calls the actual virtual function ( called thunk ).

Reference : The Annotated C++ Reference Manual, p.241 Chapter 10

Operator overloading :: class member Vs namespace member

In C++, during operator overloading, what are the conditions that affect the function from becoming a class member Vs being declared at the namespace level.

Answer:

* When an overloaded operator is a class member, the class member operator is only invoked when the operator is used with a left operand that is an object of class type. If the operator must obe used with a left operand of another type, then the overloaded operator must be a namespace member.
* The =, [], () and member access arrow "->", are required by the language to be defined as class member operators. ... and definition of any of these at namespace level will be a compile time error.

Reference : "Operator Overloading" C++ Primer Lippmann p.744

Difference between declaring a member function inside and outside the class

Difference between declaring a member function inside and outside the class..
Answer :
A member func defined inside the class in inline.( Reference : The Annotated C++ Reference Manual, section 9.3.2 p.188 )

Why Should static data members be defined outside the Class

Why Should static data members be defined outside the Class ?

Answer:

Because, static data members have external linkage, and do not belong to the class., similar to global members.( Reference : The Annotated C++ Reference Manual "Basic Concepts" p.28 )