There are as many answers to that question as there are compilers.
If you are using GCC then check out the gnu linker documentation. That describes how to set linker variables, then access those variables from C code. If the linker fills your RAM from low to high, then set a linker variable to the end of the section filled by the linker, and another to the top of the RAM, then you have the limits available to the heap. Here is an example that is more complicated than you need, it has lots of linker variables defined. Look for
The problem with this is the definition of configTOTAL_HEAP_SIZE has to
be a fixed constant at compile time. If you use heap_5 then you can set
the heap region size using a linker variable, so it automatically
adjusts as the memory map changes.
Make sure you understand your linker file. Some cruder linker files
will set the stack at the top and the heap at the bottom of any RAM that
is left over, but not dimension either of them, so they will eventually
crash in the middle if too much RAM is used.