You cannot get new heap memory without any support from the underlying operating system. I assume you have a POSIX operating system, for example. Linux
You can define your own malloc , but (in the hosted C implementation) most library functions assume that it has traditional semantics (two consecutive and successful calls to malloc without any free -s producing two unaliased pointers to separate non-overlapping memory areas).
In practice, your malloc system is usually implemented by requesting fresh segments - in multiples of 4 kilobytes of pages - from virtual memory in your address space using a system call such as MMAP (2) . But your standard C malloc tries to reuse previously free -d memory zones before calling mmap , and it allocates some βlargeβ (for example, 128 KB or 1 MB) pieces of memory using mmap and organizes them like (the details are complicated, because the details are complicated, as most malloc implementations are optimized for real common use cases). Quite often, malloc processes small secretions other than large ones. Sometimes (but more often), the malloc implementation can free up kernel memory, for example, munmap , but in practice this happens infrequently. Thus, in practice, a process that has malloc is a lot of memory in many small zones and has free -d, almost all of them still save a lot of memory (in order to be able to reuse it without any mmap ),
source share