Solved

Does function created in C take some of memory?

Posted on 1998-09-06
3
187 Views
Last Modified: 2010-04-10
Hello experts,

As I am novice to C, so I would like to ask if a recursive function created in MSVC++ occupy some of the memory spaces. If yes, how woul I clear out this function after I have use it.
By the way, does recursive function able to cause the exhaustive memory in computer..?

Thank You for the help...
0
Comment
Question by:dekoay
3 Comments
 
LVL 3

Accepted Solution

by:
LucHoltkamp earned 30 total points
ID: 1172113
In fact it does..
When the function is executed it's returnadress is saved on stack, also room for it's parameters is reserved on stack.
Because the stack is normally not as large as main memory (1 MB in win95) a stack overflow is possible, if your recursive function calls itself many times (10 of thousends in win95, but it depends on the size of your parameters).
Notice that under DOS (16 bits) the stack size is normally not larger then 64 k. So a stackoverflow is much more likely.
luc.
0
 
LVL 1

Expert Comment

by:newexpert
ID: 1172114
Any code will take up memory spaces.  Code memory is managed by the operating system therefore you don't need to worry about it.

Any function will use stack and/or heap for working.  Stack is automatically cleaned up by the function after exiting, dynamic heap needs to be freed by you (just use delete operator on anything that was created by new operator).

If you have a run-away recursive function the memory (probably on the stack) will quickly run out.  In some circumstances you get a segment violation. You can also get a stack-heap collision, and corrupt heap data, if stack and heap shares the same memory segment.
0
 

Author Comment

by:dekoay
ID: 1172115
Is there a way I can delete certain functions from the stack so there I can reuse the free space.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question