I would like to be able to determine if the pointer is on the stack or not at runtime for a number of reasons. For example, if I pass it into a function call, I can determine if I need to clone it or not. or I need to delete it.
In Microsft C (VC 6,7,8), is there a way to restrict pointer checking to see if it is on the stack or not? I'm only interested in defining this in the thread that owns the stack on which the object was placed.
sort of
static const int __stack_size and __stack_top
???? Thanks!
, , , . , , , , .
, , , , . , , , . , .
, , . , ( - - ).
, , - . .
.
, , . . isOnStack (void * ptr) , "ptr" - .
, . , , .
, .
- , .
, . . ! , ( ).
Boost. , , .
. , . /. . , .
, fastcall . . MSDN. , , . MS thiscall . & - .
, , , .
, !
, IMO . ( WIntel):
, (, ).
IsOnStack , .
abotu . , .
, boost:: shared_ptr, . ( boost , "" , ).
"" :
inline void boost_null_deleter(void *) {} template <typename T> inline boost::shared_ptr<T> unmanaged_ptr(T * x) { return boost::shared_ptr<T>(x, ::boost_null_deleter); }
Foo local = { ... }; FooPtr heapy(new Foo); FunnyFunc(unmanaged_ptr(&local)); FunnyFunc(heapy);
++, . , , - , , , , , , , , - auto_ptr boost:: shared_ptr - .
, , , , , . . , ...
-, C ++. , asm{ }.
asm{ }
-, . V++/x86 , , , ESP EBP .
ESP ( , ) , EBP (Extended Base Pointer) . x86.
, , .. , . , .
, . (EBP). - Oy V++. EBP , . .
, , , ? a ? , , , ( :-))
, , , - Gh flag. _penter .. , , , , .
, ....
. , ( ), . , .
, - .
auto_ptr , , .
MSVC Windows. , , , . , , , :)
bool __isOnStack (const void * ptr){
// FS: [0x04] 4 Win9x and NT Top of stack// FS: [0x08] 4 Win9x and NT Current bottom of the stackconst char * sTop;const char * SBot; __asm {mov EAX, FS: [04h] mov [sTop], EAX mov EAX, FS: [08h] mov [sBot], EAX
} return (sTop> ((const char *) ptr) && ((const char *) ptr)> sBot);
}