RE: Function to see if a pointer is on the stack
"Jacob Turner \(Core Design Ltd\)" <[email protected]>
| Newsgroups | gmane.games.devel.windows |
|---|---|
| Message-ID | <[email protected]> |
Yes and unfortunately I can't use ref counted technique. What we are using this for is: when we construct hash'es from a string we save the string ptr in a map table so we can go back from a hash value to a string to aid debugging. This fails if the string was constructed on the stack. So now we are copying the string to our own string table and saving the pointer to the copy. But in a quest for optimisation (because we are cross-platform and want to run on some console h/w with no extra debug memory) we only want to copy the string to our string table if the string is on the stack, because for strings from static data then the pointer is valid. I think for now we will just make the PC function return TRUE and write correct versions for other consoles which need it. In fact we might just ditch the whole thing are just always use the string table because it doesn't require that much space (~8KB) and I have also thought of a situation where the copying of the pointer would fail even for non-stack strings. For hash'es made from strings in a loaded in from an asset file then the pointer could be invalid because we allow our asset files to get moved around in memory. Thanks anyway Jake > -----Original Message----- > From: [email protected] > [mailto:[email protected]]On Behalf Of > Andrew Grant > Sent: 20 August 2004 12:53 > To: [email protected] > Subject: RE: [GD-Windows] Function to see if a pointer is on the stack > > > > I think Jon's point wasn't necessarily to use std::string, > but to use a > refcounted technique with something like a smartpointer. That > ensures that > your encapsulated data stays alive as long as the > smartpointer does - which > can be returned, passed back by reference and so on. > > Consoles are easy as you can control where the stack goes > yourself and check > the range (for instance on PS2 our main thread's on the top > half of the > scratchpad) but trying something like this on Windows would > fill me with > dread :) > > I'm curious as to what you're trying to do though, I can see > the case with > strings where e.g you might want to format and return an > error message (we > do this and have a string class with derivatives for stack > usage and heap > usage which understand each other and know how to handle the > situation of > e.g passing a string which was build up on the heap). > > > _____________________________ > andrew grant > lead programmer, climax brighton > > > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On > Behalf Of Jacob > Turner (Core Design Ltd) > Sent: 20 August 2004 12:29 > To: [email protected] > Subject: RE: [GD-Windows] Function to see if a pointer is on the stack > > 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: [email protected] > > [mailto:[email protected]]On > Behalf Of > > Jon Watte > > Sent: 19 August 2004 18:19 > > To: [email protected] > > Subject: RE: [GD-Windows] Function to see if a pointer is > on the stack > > > > > > 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! > > > > 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. > > > > // non-threaded version -- if you use threads or fibers, // > you need > > one gBase per thread/fiber > > > > char * gBase; > > > > void register_main( char * base ) { > > gBase = base; > > } > > > > bool is_stack_pointer( char const * ptr ) { > > char top[10]; > > assert( top < gBase ); // else stack grows up > > return (ptr < gBase) && (ptr > top); } > > > > int main() { > > ... > > char junk[ 10 ]; > > register_main( junk ); > > ... > > } > > > > void some_func( char * anArg ) { > > if( is_stack_pointer( anArg ) ) { > > ... > > } > > } > > > > > > -----Original Message----- > > From: [email protected] > > [mailto:[email protected]]On > Behalf Of > > Jacob Turner (Core Design Ltd) > > Sent: Thursday, August 19, 2004 9:30 AM > > To: [email protected] > > Subject: [GD-Windows] Function to see if a pointer is on the stack > > > > > > Is there some simple and reliable code for a console or > windows app to > > test if a pointer value is on the stack or not ? > > > > If the pointer is on the stack (e.g. a string) then we want to copy > > the string to heap memory for reuse later on. > > > > Cheers > > > > Jake > > > > > > ------------------------------------------------------- > > 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 > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_idU5 > > > > > > > > ------------------------------------------------------- > > 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 > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > > Archives: > > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > > > > > ------------------------------------------------------- > 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 > [email protected] > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_idU5 > > > ------------------------------------------------------- > 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 > [email protected] > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > ------------------------------------------------------- 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 [email protected] https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows Archives: http://sourceforge.net/mailarchive/forum.php?forum_idU5