- c++ problem with dynamic and static object - 16 Updates
- c++ problem with dynamic and static object - 1 Update
"Öö Tiib" <ootiib@hot.ee>: Jul 24 05:04PM -0700 On Saturday, 25 July 2020 01:27:56 UTC+3, Keith Thompson wrote: > That's probably good enough to distinguish between them *for > debugging purposes*. But making a program's behavior depend on > such a distinction is likely to be a bad idea. Basically I agree with your "no". For example stacks: It is commonly possible to inspect sizes and locations of stacks of threads of program in platform-specific manner. That makes it also possible to find out if a pointer points into one of stacks or not. The pthreads or boost::thread let to do most of it portably. So in practice it is often possible. But as "automatic storage" of C++ has to be implementable on esoteric system without stacks whatsoever and so can have whatever unimaginable layout then in theory it is impossible. ;) |
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Jul 24 06:10PM -0700 Öö Tiib <ootiib@hot.ee> writes: [...] > esoteric system without stacks whatsoever and so can have > whatever unimaginable layout then in theory it is > impossible. ;) One source of confusion is that there are (at least) two distinct meanings of "stack" (and the standard doesn't use either of them, though it does refer to "stack unwinding"). One is a contiguous region of memory that grows and shrinks, with new memory allocated and deallocated only at the "top", typically managed by a "stack pointer" which may or may not be a dedicated CPU register. The direction in which a stack grows is unspecified. Most C++ implementations have a "stack" in this sense, but that's an implementation detail. Another is a more generic term referring to a data structure with stack-like last-in/first-out semantics. Objects with automatic storage duration are allocated and deallocated in a stack-like manner. Most implementations use a "stack" (in the first sense) to implement this stack-like behavior. Others might, for example, allocate activation records for function invocations dynamically (on the "heap"), resulting in no consistent relationship between addresses of objects in nested invocations. (And I'm ignoring threads here.) People who talk about "the stack" usually refer to the first sense of the word. Code that assumes that there's such a thing as "the stack" is likely to be (a) non-portable to exotic platforms and (b) unnecessarily low-level. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */ |
Scott Newman <scott69@gmail.com>: Jul 25 05:00AM +0200 Use the is_heap-operator. |
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Jul 25 04:31AM +0100 On 25/07/2020 04:00, Scott Newman wrote: > Use the is_heap-operator. Fuck. Off. /Flibble -- "Snakes didn't evolve, instead talking snakes with legs changed into snakes." - Rick C. Hodgin "You won't burn in hell. But be nice anyway." – Ricky Gervais "I see Atheists are fighting and killing each other again, over who doesn't believe in any God the most. Oh, no..wait.. that never happens." – Ricky Gervais "Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Byrne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?" "I'd say, bone cancer in children? What's that about?" Fry replied. "How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil." "Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say." |
Scott Newman <scott69@gmail.com>: Jul 25 07:47AM +0200 >> Use the is_heap-operator. > Fuck. Off. Why ? Because I show the real solutions and you don't ? |
aotto1968 <aotto1968@t-online.de>: Jul 25 07:54AM +0200 On 24.07.20 21:01, aotto1968 wrote: > it is possible (with gcc) to find out if a instance was created on a > "stack" or on a "heap" * > ;-) ok -> why I need this Info ? I have a method that is called "Delete()". and now I need this information if "myA.Delete()" should do an "delete myA" or just release the internal data and keep the outer shell alive. mfg |
Bonita Montero <Bonita.Montero@gmail.com>: Jul 25 09:05AM +0200 Maybe something like this would help (only suitable for the thread calling): #include <intrin.h> inline bool in_our_stack( void *addr ) { void *stackBottom, *stackTop; #if defined _MSC_VER #if defined(_M_IX86) stackBottom = (void *)__readfsdword( 0x04 ); stackTop = (void *)__readfsdword( 0x08 ); #elif defined(_M_X64) stackBottom = (void *)__readgsqword( 0x08 ); stackTop = (void *)__readgsqword( 0x10 ); #else #error "unsupported MSC-CPU"
Subscribe to:
Post Comments (Atom)
|
No comments:
Post a Comment