Solved

Does function created in C take some of memory?

Posted on 1998-09-06
3
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

705 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