Skip to main content
gamedev.net
🔒 Locked

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

Started by psykr 7 replies 1.1k views
Original Post
psykr
psykr
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?
brassfish89
brassfish89
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
rohde
rohde
You have to post the code if you want some comments.



"Yeah, I would''ve killed you, but I''m glad I didn''t - the paperwork is a bitch"
"We confess our little faults to persuade people that we have no large ones." -Francois de La Rochefoucauld (1613 - 1680). | My blog
noVum
noVum
You only have the base address to distinguish between a heap and a stack pointer, so this is very OS specific.
JD
JD
Create your own memory pool, if the pointer doesn''t point into it then it''s on the stack Seriously, I have no idea.
LessBread
LessBread
Maybe this will help: Object On The Stack.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Jingo
Jingo
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.
psykr
psykr
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.