RE: [GD-Windows] Function to see if a pointer is on the stack
Brought to you by:
vexxed72
From: Jacob T. \(C. D. Ltd\) <Ja...@Co...> - 2004-08-20 11:27:27
|
Unfortunately can't do the reliable method. My example for copying = strings is just an example so can't use std::string<> or bare pointer = technique. Bit scared about the other option because we are in a multi-threaded app = and this function would be common to all threads and we don't have = explicit creation of common library stuff when a new thread is made. Isn't there a really PC specific code e.g. getting the stack ptr etc. = This is how I am doing the function on consoles. Mind you not a big hassle because on the PC we have so much memory that = don't care if just always copy strings or whatever data i.e. can make is = variable on stack function return TRUE all the time. Thanks Jake > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...]On Behalf Of > Jon Watte > Sent: 19 August 2004 18:19 > To: gam...@li... > Subject: RE: [GD-Windows] Function to see if a pointer is on the stack >=20 >=20 > The most reliable way of doing this is to use a class for > your argument rather than bare pointers, and have a > constructor from bare pointers, and use reference counting > in the class implementation -- this is almost exactly what > std::string<> already does for you! >=20 > Else, you can register the stack pointer in main() (or the > entry function for each thread/fiber), and get the stack > pointer in the called function, and compare -- this is not > entirely portable, because the stack may grow up on some > architectures. >=20 > // non-threaded version -- if you use threads or fibers, > // you need one gBase per thread/fiber >=20 > char * gBase; >=20 > void register_main( char * base ) { > gBase =3D base; > } >=20 > bool is_stack_pointer( char const * ptr ) { > char top[10]; > assert( top < gBase ); // else stack grows up > return (ptr < gBase) && (ptr > top); > } >=20 > int main() { > ... > char junk[ 10 ]; > register_main( junk ); > ... > } >=20 > void some_func( char * anArg ) { > if( is_stack_pointer( anArg ) ) { > ... > } > } >=20 >=20 > -----Original Message----- > From: gam...@li... > [mailto:gam...@li...]On Behalf Of > Jacob Turner (Core Design Ltd) > Sent: Thursday, August 19, 2004 9:30 AM > To: gam...@li... > Subject: [GD-Windows] Function to see if a pointer is on the stack >=20 >=20 > Is there some simple and reliable code for a console or=20 > windows app to test > if a pointer value is on the stack or not ? >=20 > If the pointer is on the stack (e.g. a string) then we want=20 > to copy the > string to heap memory for reuse later on. >=20 > Cheers >=20 > Jake >=20 >=20 > ------------------------------------------------------- > SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media > 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 > Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. > http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_idU5 >=20 >=20 >=20 > ------------------------------------------------------- > SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media > 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 > Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. > http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=3D555 >=20 |