Re: What's the difference between the heap and the freestore?

From: Dave Moore (dtmoore_at_rijnh.nl)
Date: 05/10/04


Date: 10 May 2004 06:04:33 -0700

Jorge Rivera <jorgeri@rochester.rr.com> wrote in message news:<lhsnc.17982$hY.13605@twister.nyroc.rr.com>...
> In general, when discussing dynamically allocated memory, I hear people
> referring to the heap. As of a couple of days ago, I though the heap
> was shared by new and malloc.
>
> I know that new must provide more information about the type of memory
> allocated than malloc, etc. However, can somebody explain in more
> details the differences between the heap and the freestore?
>
> I am interested in:
>
> 1. Do the heap and the freestore redside in different memory segments?
> 2. What information is stored in the freestore?
> 3. Why are the terms used interchangeably in most groups?

As I understand it, there is no conceptual difference between the
so-called 'heap' and 'free-store'. They are both used to refer to the
pool of memory from which a C++ program allocates storage for dynamic
objects. OTOH, according to Herb Sutter's GotW (I think #9), there is
a conventional difference between them in the C/C++ community, in that
'free-store' and 'heap' are generally used to refer to the pools of
memory from which operator new and malloc allocate objects,
respectively. One important thing to note is that these pools are not
required to be identical ... AFAIK they can in practice be distinct,
identical or overlapping. That is why you sometimes see questions
about whether memory allocated for objects using new can be
de-allocated using free (it is not safe practice to do so).

Now, I will say that is was old GotW, which pre-dates the Standard,
but I have since seen the conventions used elsewhere.

HTH, Dave Moore



Relevant Pages

  • Re: simplest dynamic memory manager / allocator
    ... You might find that 4tH doesn't reserve much memory for dynamic ... memory is allocated at the heap, ... 768 allocates 64 bytes. ... Every fragment is represented by a cell in the HAT. ...
    (comp.lang.forth)
  • Re: stack and a heap
    ... > When an application is opened Windows allocates the full 32 bit address ... > space of memory. ... > into two parts, the Stack and Heap. ... The instaniated Object in writen to the Heap. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: LocalFree Fails to Release Memory
    ... If you call LocalAllocfrom managed code, that allocates from ... If you grow that heap really, really big and then free some ... does any of the memory get released to the OS? ... I read about the memory management, and my idea was ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Stack or Heap
    ... >>> available memory, return addresses, parameter passing and the like. ... >>> coming out of the heap is allocated in more or less arbitrarily sized ... > allocates its memory". ... > "The stack" is a misnomer since some implementations don't have one. ...
    (comp.lang.c)
  • Whats the difference between the heap and the freestore?
    ... In general, when discussing dynamically allocated memory, I hear people ... As of a couple of days ago, I though the heap ... Do the heap and the freestore redside in different memory segments? ...
    (comp.lang.cpp)