468,290 Members | 1,849 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

where does function reside in memory in C++

Hi all,

I know that some variables are stored on heaps and some on
stack in C++. How about functions? where does function
reside on memory? Is it stack or heap?

And are both function (not class member) and method
(function in a class) stored in the same location (either
stack or heap)?

Thank you very much in advance.

regards,
Sean
Nov 17 '05 #1
2 1454
"Sean" <an*******@discussions.microsoft.com> wrote in message
news:7e****************************@phx.gbl...
I know that some variables are stored on heaps and some on
stack in C++. How about functions? where does function
reside on memory? Is it stack or heap?
Neither. When you run an application, Windows' loader inspects the image
file, pre-allocates memory and copies the binary executable (functions and
all) into the memory. This memory is not considered to be stack or heap. Why
do you want to know?
And are both function (not class member) and method
(function in a class) stored in the same location (either
stack or heap)?


As above.

I sense a bit of confusion, here. :-)

Stack and heap are used for dynamic allocations though most stack
allocations have much shorter lifetimes, functions tend to "live" for the
life of an application.

Regards,
Will
Nov 17 '05 #2
Hi Will,

Thanks for your reply.
I'm just curious since we ocassionally have function
pointers and I was wondering where
the pointers point to? :)

regards,
Sean
-----Original Message-----
"Sean" <an*******@discussions.microsoft.com> wrote in messagenews:7e****************************@phx.gbl...
I know that some variables are stored on heaps and some on stack in C++. How about functions? where does function
reside on memory? Is it stack or heap?
Neither. When you run an application, Windows' loader

inspects the imagefile, pre-allocates memory and copies the binary executable (functions andall) into the memory. This memory is not considered to be stack or heap. Whydo you want to know?
And are both function (not class member) and method
(function in a class) stored in the same location (either stack or heap)?
As above.

I sense a bit of confusion, here. :-)

Stack and heap are used for dynamic allocations though

most stackallocations have much shorter lifetimes, functions tend to "live" for thelife of an application.

Regards,
Will
.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Jonas Rundberg | last post: by
37 posts views Thread by Ben | last post: by
6 posts views Thread by Marcus | last post: by
8 posts views Thread by lasek | last post: by
7 posts views Thread by puzzlecracker | last post: by
43 posts views Thread by Kislay | last post: by
5 posts views Thread by Anane | last post: by
25 posts views Thread by sidd | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.