• Advertisement


This topic is now archived and is closed to further replies.

[ASM] Will my singleton really reduce to a single dereference?

This topic is 5697 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m curious as my code is littered with things like this: CRenderer::GetInstance().SetRenderState(Colour); CRenderer::GetInstance().SetRenderState(Culling); CRenderer::GetInstance().SetRenderState(Lighting); CRenderer::GetInstance().SetRenderState(Material); CRenderer::GetInstance().SetRenderState(Shade); CRenderer::GetInstance().SetRenderState(Alpha); It''s easy to cut ] paste, and to me at least it looks neater that taking a pointer an using that. What I''m curious about is will the following function really reduce to a pointer dereference in a release build. Why ask? Why not check myself? Two reasons: 1) I seem to be only able to generate asm files in debug mode. In release they just don''t appear, I made the settings, all i get is the obj files though(.NET) 2) I can barely read asm anyway... Here is the simple code snippet:
template <class T>
inline T& CSingleton<T>::GetInstance(void)
	return *s_Instance;
Now I''m sure the assert will disappear, that only leaves the inlined function to reduce flatten out to nothing. Can anyone else confirm that what I have above is no more evil than simple pointer deferences? Many thanks, Chris Brodie http:\\fourth.flipcode.com

Share this post

Link to post
Share on other sites

  • Advertisement