473,834 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1662
"Sean" <an*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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
5055
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
5038
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 signature. When developing this lib, I figured that the pointer-to-member-function, although seemingly an attractive solution, does not work well for us.
6
2121
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 accessible in $_COOKIE. I cleared all cookies in my Cookies folder before starting the session, and everytime I run the script it does not create a cookie in the folder. For testing I even set the browser to accept all cookies to make sure. ...
5
2619
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: int hi() { return 0; }
8
10868
by: lasek | last post by:
Hi...in some posts i've read...something about using macro rather then function...but difference ??. Best regards....
7
2215
by: puzzlecracker | last post by:
Dynamically allocated objects reside on a heap, local objects on a stack. What about static objects? Thanks
43
5217
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 last reference . 2.Global variables exist in the initialized data segment .
5
1553
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 objects of class C. Application Flow: 1. Application reads some inputs.
25
2677
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
9649
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10554
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10224
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9338
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7761
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5629
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4428
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.