On Wed, Jun 3, 2009 at 6:38 AM, Rick Altherr <kc8...@kc8apf.net> wrote: > I'm speaking in general terms, but, yes, simple accessors can definitely be > a problem depending how the program is structured. I've seen many a game > engine written in C++ with full encapsulation where a statistical profile > shows nearly all of the time in the prolog and epilog. The actual accessor > doesn't cost anything (maybe 1-2 instructions), but the setup for the stack > frame kills it. A stack frame setup forces accesses to memory so even > though the number of instructions is small, the impact on the performance is > significant. Having the instructions sit in the icache does help in terms > of instruction fetch times, but the data operations involve a > read-modify-write pattern which won't sit well in many cache structures. > > To be entirely fair, this problem with accessors mainly shows up when there > are a large number of instances of the object and the accessor is being > called as part of a traversal over the instances. > > The typical solution is to allow direct access to the data member to avoid > the stack frame setup/teardown overhead.
Wouldn't you have the accessor as inlined member function in C++ (while keeping the data private)? Michael _______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development