Behind dynamic memory allocation

Hello everybody,
I'm making 15 minutes lesson on dynamic memory management in c/c++.
I wonder if someone knows how really malloc() function or new works.
I found out that it depends on what OS we're in so I would like to know about windows.
Another question I want to ask: Is the malloc() or new using some API function or they just approach the RAM memory themself?

Real thanks, TheTufik
Last edited on
The heap works by obtaining large chunks of memory and handing out chunks of it on demand. We call this sub-alllocation.

The heap must keep track of what blocks it has given out and how large they are.
It must cope with concurrent threads of access.
It must keep a record of all the large blocks it has itself requested.
It should try to reduce fragmentation.
It must deal with allocations and returns happening out of order.
It may want to consider returning large blocks back the to the OS if all the suballocations have been returned.
It may want to provide diagnostics to assist int he debugging of errant applications.

Additionally:
These arrangements are the same across OS', what changes is how they interface to the OS.

The BSD allocator on Solaris doesn't deal with multi-threading, so multi-threaded apps can't use that allocator.

If can be tricky to be good at dealing with small blocks and be good at dealing with large blocks at the same time.
Topic archived. No new replies allowed.