Is there any way I can write a wrapper that wraps around a piece of code and evaluates how much memory has been used after the execution? Ideally I would like a function that performs the following operation
m0=MemoryinUse[];
temp=Table[Random[], {i,1,10000}];
output=MemoryinUse[]-m0
The code to be input in this function has to be arbitrarily long.