Re: dynamically-allocated memory is uninitialized

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/11/2016 08:04, nick wrote:

> On 2016-11-12 01:37 AM, Andrew Pinski wrote:
>
>> Anyways I think the problem is you assume
>> new Record*[N]; will NULL out the array.  It does not.
>
> Shouldn't new overwrite that memory with a null block
> or is new so stupid that it doesn't do this [...]

Hello,

First, while compiler bugs (or bugs in low-level supporting libraries)
do exist, they are rare. Bugs lurk in user code 99.44% of the time.
(I'm told that's a real statistic.)

Second, you expect dynamically-allocated memory to be zeroed. Consider the
case where an app requests a large memory block, and intends to initialize
it to non-0 values. Zeroing such a block would be a pure waste of CPU.

cf. also short-comings of strncpy()

Regards.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux