Archived

This topic is now archived and is closed to further replies.

Is pointer stack allocated? (C/C++)

This topic is 5130 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I found some code I''d saved for determining if a pointer is stack allocated or not (I assume it''s for determining whether it''s safe to delete a given pointer), but I''m afraid I don''t understand it at all. Could anyone explain to me how this pointer arithemetic works, and whether it''s possible for me to condense this code into a single function?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Uhhh, yeah. I''ll tell you how it works without seeing the code.

Share this post


Link to post
Share on other sites
Wow, I didn''t know there is way to tell whether data is on the heap or the stack. Can you post the code? It sounds like a nice thing to have

--------
"Hey, what about those baggy pants you kids are wearin'' these days? Aren''t they hip and cool and poppin'' fresh?"-Peter Griffin
"Everytime I see an M followed by a dollar sign I just say "oh god" and go to the next post."-Neurokaotix
the D programming language

Share this post


Link to post
Share on other sites
Create your own memory pool, if the pointer doesn''t point into it then it''s on the stack Seriously, I have no idea.

Share this post


Link to post
Share on other sites
Just because an object isnt allocated on the stack doesn''t mean it can be safely deleted. Most implementations have an area for global variables, an area for static variables, as well as the heap. If an object isnt on the stack, it could be in either of these areas of memory, and so it cannot be safely deleted until you know for sure it is on the heap. As far as i know there is no completely safe and portable solution to this problem.

Share this post


Link to post
Share on other sites
Right.. I forgot the code.. anyway, it''s the code from that flipcode article that was mentioned earlier in the thread. My problem with it was that it just seemed too long; it had functions that I believed could be condensed into one, but I didn''t understand what it was doing, so I couldn''t safely do what I wanted with it.

Share this post


Link to post
Share on other sites