How can we dynamically determine 1) either in bytes or 2) percentage of total available memory used during the run-time of a C/C++ program.

I am using an iterative computational & memory intensive algorithm. The memory / computational needs for the nth iteration can only be determined at the (n-1)th and nth iteration.

Hence cannot pre-calculate the memory utilization. Any pointers will be helpful.

Thanks,