When and why will an OS initialise memory to 0xCD, 0xDD, etc. on malloc/free/new/delete?

Posted by LeopardSkinPillBoxHat on Stack Overflow See other posts from Stack Overflow or by LeopardSkinPillBoxHat
Published on 2008-12-16T00:41:59Z Indexed on 2010/05/13 9:24 UTC
Read the original article Hit count: 272

Filed under:
|
|
|

I know that the OS will sometimes initialise memory with certain patterns such as 0xCD and 0xDD. What I want to know is when and why this happens.

When

Is this specific to the compiler used?

Do malloc/new and free/delete work in the same way with regard to this?

Is it platform specific?

Will it occur on other operating systems, such as Linux or VxWorks?

Why

My understanding is this only occurs in Win32 debug configuration, and it is used to detect memory overruns and to help the compiler catch exceptions.

Can you give any practical examples as to how this initialisation is useful?

I remember reading something (maybe in Code Complete 2) that it is good to initialise memory to a known pattern when allocating it, and certain patterns will trigger interrupts in Win32 which will result in exceptions showing in the debugger.

How portable is this?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c