Solved

Does function created in C take some of memory?

Posted on 1998-09-06
3
183 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now