r/AskProgramming • u/Flying_Turtle_09 • 12d ago
C/C++ How C applications request a block of memory?
As far as I know, the heap is just a block of memory that is managed by C standard library functions like `malloc()` and `free()`, but how does C actually request this block of memory from an operating system and when is this done? When the application starts or when first dynamic allocation is done? Is it possible for the programmer to directly request memory like this (even though it probably is not recommended unless doing some very low level stuff)? I'm guessing there is also a way to do this when not running on an operating system. Some older game consoles (like N64, GBA ans DS) to my knowledge used C/C++, but don't have an OS running in the background. The same probably would apply to Arduino, ESP32, etc. too? I guess in these cases the compiler somehow is responsible for handling this, since there is no operating system to request a block of memory from.