Is there a way of checking if memory pointed to by pointer has been initialized?(not necessarily by my program).
Thanks
Asked
Active
Viewed 1,265 times
1
There is nothing we can do
- 1
- 28
- 98
- 186
-
What's your test for "initialized"? All zeroes? – S.Lott Mar 31 '10 at 15:41
4 Answers
7
No.
Uninitialized memory can contain anything, including bytes that make it look like it has been initialized.
James McNellis
- 338,529
- 73
- 897
- 968
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
- 41,802
- 29
- 133
- 165
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
- 248,051
- 86
- 340
- 401
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
- 202,568
- 34
- 375
- 539