.net - How do I find the amount of memory allocated by a method? -


i'd know total amount of memory allocated while method runs. far have:

gc.collect() gc.waitforpendingfinalizers() memstart = gc.gettotalmemory(false) f() memend = gc.gettotalmemory(false) print (memend - memstart) 

this seems work enough simple functions when f allocates forces collection result excludes collected objects. not that, there no way of telling "overflow" happened.

is there easy way this? without buying/installing/configuring memory profiler? stopwatch allocator/collector ideal. do:

sw = new gcstopwatch() sw.start() f() sw.stop() print sw.totalbytesallocated print sw.numberofcollections // etc 

i want can find out how pressure method putting on garbage collector. code reading numbers fixed length string using lots of calls along lines of int32.parse(s.substring(4,6)) , considered doing parsing in-place introducing parseint(string s, int startindex, int length) avoid allocating tens of thousands of substrings. nice tool have in other scenarios too.

i've used performance counters these kind of analysis. not perfect enough.

gc.collect() gc.waitforpendingfinalizers() 

those 2 lines won't wait garbage collector finish. , garbage collection might occur during you're function call anyway. might better measure performance/time optimisation.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -