473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 1635
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
6
by: Marcus | last post by:
Hello all, This is baffling me. I am starting a session and I know it is setting a cookie on my computer - I called getallheaders() and see that it is setting the cookie, and it is also...
5
by: tkk | last post by:
Hi All, Is it possible to load a function at a particular address/memory through the source program specification itself (or) is it upto linker/loader combination which decides this? For ex:...
8
by: lasek | last post by:
Hi...in some posts i've read...something about using macro rather then function...but difference ??. Best regards....
7
by: puzzlecracker | last post by:
Dynamically allocated objects reside on a heap, local objects on a stack. What about static objects? Thanks
43
by: Kislay | last post by:
Which of the following is correct regarding the storage of global variables : 1. Global variables exist in a memory area that exists from before the first reference in a program until after the...
5
by: Anane | last post by:
In my application I have 3 classes. 1. class A 2. class B 3. class C Application controller (having main function) has the object of class A, class A has object of class B and class B has...
25
by: sidd | last post by:
In the following code: int i = 5; ---it goes to .data segment int j; ---it goes to bss segment int main() { int c; int i = 5; ---stack
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.