Domanda

This reddit thread has drawn my attention on custom memory allocators. User Rohmboid says, for instance:

People wouldn't be writing their own pool allocators it if there wasn't a clear benefit.

How do they know there is one?

I don’t want to waste my time/money/energy on writing a custom allocator if the time spent managing memory only accounts for less than 1% of the duration of my program. Neither do I want to switch to a custom allocator and be unable to tell the speedup. So I am wondering: how can I measure (or at least, estimate) the time spent allocating/freeing/fetching memory?

È stato utile?

Soluzione

How do I know there is one?

Profile your code.

There's no point optimizing something that isn't a hot path in your code.

If the Allocator (A) takes 5% of your CPU time, and your app takes the other 95%, speeding the allocator up twice gives you (5/2)/100 = 2.5% boost. Now try to speed up B by even a fraction.

How?

The easiest way is to use the IDE built-in profiler; MSVS one is rather decent, although I am using Intel VTune; its ease of use is really great, and it just shows you - optimize here.

Using the profiling program has the additional benefit; you don't have to modify your code at all; you also don't have to recompile when you want to change profiling options and run again. That being said, timers in your application can also give nice results, although they rarely need to be placed directly inside allocator. It's better to continuously narrow the possible places where the program takes the most time.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top