Which part of the computer allocates memory in RAM?
It is a combination of the standard C library (usually) and the operating system. No hardware is involved. Check out this answer on stackoverflow for more details.