1

Is there a way of checking if memory pointed to by pointer has been initialized?(not necessarily by my program).
Thanks

There is nothing we can do
  • 23,727
  • 30
  • 106
  • 194

4 Answers4

7

No.

Uninitialized memory can contain anything, including bytes that make it look like it has been initialized.

James McNellis
  • 348,265
  • 75
  • 913
  • 977
1

The only way would be to define a "not initialized value", such as 0x0 (just because), and use that inside your application, setting all the memory you ask for with that value.

In general, no, not possible.

Tom
  • 43,810
  • 29
  • 138
  • 169
0

By "initialized" you probably mean "allocated". In any case: no, it isn't possible.

If the pointer is NULL, you can say it wasn't initialized for sure, however :-)

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412
0

Not really. You might be able to do something low-level and OS-specific, like see if touching the memory generates a page fault, but I can't believe that anyone would seriously contemplate doing something like this when there must be a better overall solution.

Paul R
  • 208,748
  • 37
  • 389
  • 560