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
Solved

Does function created in C take some of memory?

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

808 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