I'm implementing an algorithm that needs to run under a hard memory limit of 4MB.
Is there a way to run a process in a way that it would get killed if it over-reaches its memory limit? Or simply just profile its allocations to be able to see how much maximum memory has been allocated?