Re: Heap? what does it mean?
From: SaltPeter (SaltPeter_at_Jupiter.sys)
Date: 07/10/04
- Next message: Jerry Coffin: "Re: IO-Operator overloading question"
- Previous message: Jarek: "Re: Default constructors, passing argument"
- In reply to: Firewalker: "Re: Heap? what does it mean?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
> >
> >
> >
>
>
- Next message: Jerry Coffin: "Re: IO-Operator overloading question"
- Previous message: Jarek: "Re: Default constructors, passing argument"
- In reply to: Firewalker: "Re: Heap? what does it mean?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|