new is oftentimes implemented on basis of malloc/free.
How does malloc/free implement it? The answer is: It depends on the implementation. Surprisingly: Malloc oftentimes does not keep track of the allocated blocks at all! The only thing, malloc is doing most of the time, is adding a little bit of information containing the size of the block "before" the allocated block. Meaning, that when you allocate 40 bytes, it will allocate 44 bytes (on 32bit machines) and writes the size in the first 4 bytes. It will return the address of this chunk+4 to you.
Malloc/free keeps track of a freelist. A freelist is a list of freed memory chunks that is not (yet) be given back to the operating system. Malloc searches the freelist, when a new block is needed and when a fitting block is available uses that.
But a more exhausting answer about malloc/free, I have given here:
How do malloc() and free() work?
One additional information:
One implication of the fact, that many allocators don't track allocated blocks: When you return memory by free or delete and pass a pointer in, that was not allocated before, you will corrupt your heap, since the system is not able to check if the pointer is valid. The really ugly thing about it is, that in such a case, your program will not dump immediately, but any time after the error-cause occured ... and thus this error would be really ugly to find. That is one reason, memory handling in C/C++ is so hard!
newallocates memory is an implementation detail by the compiler vendor. Somenewimplementations usemalloc()internally, some don't. But rarely do any of them go directly to the OS, there is usually a runtime library in between, managing memory allocations (amongst other things). Code should not care on way or the other. It asks the compiler tonewsome memory, and gets a pointer in return. How the memory is managed is up to the compiler to decide.delete, the block is added back to the free list.mallocandfreewere just requests to the OS. Most can't do it very efficiently, however, so for efficiency reasons,mallocandfreetypically allocate from large, in process memory blocks. Unless you request something very big; it's not unusual formallocto go directly to the OS for something like a couple of mega.