Re: Heap? what does it mean?

From: SaltPeter (SaltPeter_at_Jupiter.sys)
Date: 07/10/04


Date: Fri, 9 Jul 2004 20:26:27 -0400


"Firewalker" <hana1@rogers.com> wrote in message
news:OawHc.823554$Ar.367252@twister01.bloor.is.net.cable.rogers.com...
> Thanks a lot guys, that was really helpful. I kept seeing it and don't
> understand what exactly it refers to. Now I believe I understand the
> concept. Thanx again

Don't mention it. By the way, now you know why an application that allocates
storage on the heap but fails to free it eventually generates "not enough
resources available" or not enough memory exceptions. The moral of the story
is: keep track of what you allocate on the heap. Also, when you get the
chance, look up the subject of "Smart Pointers".

>
>
> "SaltPeter" <SaltPeter@Jupiter.sys> wrote in message
> news:_hsHc.47992$JG5.1211239@news20.bellglobal.com...
> >
> > "Snake" <hana1@rogers.com> wrote in message
> > news:cEoHc.817698$Ar.707596@twister01.bloor.is.net.cable.rogers.com...
> > > Hello experts,
> > > I have a quick question about a thing that I am not sure I fully I
> > > understand. What does a heap mean?I mena when it says, the memory
> > location
> > > was allocated on the heap, then what does that mean?
> > > Thank you for your help in advance
> > >
> >
> > Heap refers to an area of memory reserved for dynamic allocations(the
free
> > store). But thats a simple explanation.
> >
> > Should you declare a variable in code, that variable is allocated
staticly
> > in an area reserved by your compiler to serve static
allocations(sometimes
> > called a stack).
> >
> > int i = 5;
> >
> > is not reserved on the "heap" and is automatically destroyed when its
> scope
> > ends. But if you were to say:
> >
> > int *p = new int(5);
> >
> > You are asking the compiler to allocate space for an int, initialize to
5
> > and return a pointer p to it. Whats different is
> >
> > a) this allocation isn't destroyed at the end of the scope its in.
> > b) the dynamic allocation takes place in a different area of memory(the
> free
> > store)
> > c) you've taken the responsability to deallocate that variable with:
> >
> > delete p;
> >
> > If you compile code that both allocates variables staticly and
> dynamically,
> > debugging the code and observing the variable's addresses will expose
the
> > distinct memory areas provided by the compiler for each type of
> allocation.
> >
> > Heap is usually associated with C code, but not neccessarily(C provides
> ways
> > to allocate dynamically on the stack as well). There is no simple
> > explanation for heap since memory management is not limited to a static
> and
> > a dynamic memory area defined by a compiler and the configured memory
> model.
> >
> > The complexities involved with the definition of heap appears when
> creating
> > your own memory management. It sometimes happens that a coder needs to
> > provide his own memory management policies (overloaded new operator,
etc).
> > Here is an article that describes such a scenario:
> > http://www.cantrip.org/wave12.html
> >
> >
> >
>
>



Relevant Pages

  • Re: Lcc-win32 extensions to C
    ... compiled with a C++ compiler or a C compiler. ... Yes, but if you do not use GC, you allocate more memory than needed to ... Using a non-GC'ed heap+ a GC'ed heap requires also more memory... ... Collector, since GC technologies are much more advanced than simple ...
    (comp.std.c)
  • Re: Huge pages and small pages. . .
    ... >> what looks like contiguous memory and away you go. ... you need to have them cached in the TLB; if the TLB runs out of ... > low end of the heap, until someone figures out a way to tell the system ... When you allocate memory, the kernel just marks a promised ...
    (Linux-Kernel)
  • Re: run-time vs compile-time
    ... > offset related to some location (like stack base) somewhere. ... > offset from heap to pi. ... When you allocate an int on the heap, it is allocated at address 1. ... application has a given amount of memory it can use as it wishes. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: run-time vs compile-time
    ... > offset related to some location (like stack base) somewhere. ... > offset from heap to pi. ... When you allocate an int on the heap, it is allocated at address 1. ... application has a given amount of memory it can use as it wishes. ...
    (comp.lang.cpp)
  • Re: Mex Overflow Error Using Free Borland Compiler
    ... >>Borland compiler handles overflow errors. ... >>The first thing I tried is dynamic memory allocation. ... 1- You declare the variables of type double and allocate of size long double. ... would clean up a lot of code by eliminating the pointer dereferences. ...
    (comp.soft-sys.matlab)