tags:

views:

116

answers:

4

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

A: 

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
A: 

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
+8  A: 

No.

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

James McNellis
A: 

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