Sign in to follow this  
AshleysBrain

File & Line macros in member function

Recommended Posts

I'm writing a DirectX display class that includes texture loading functions. Unmanaged C++, VS 2008, D3D 9. In the past tracking textures and VRAM leaks have been an issue, so I'd like to code an allocation tracker which can report leaks in VRAM. As I understand it, this is done with 'new' in C++ via the __FILE__ and __LINE__ macros, as in something like: #define new new(__FILE__, __LINE) which causes an overload of 'new' to track the file and line of the allocation so it can report a memory leak. I think 'delete' does a similar thing. However in my case I have a member function, like: DisplayClass.CreateRenderTargetTexture(128,128); to create a 128x128 texture. How can I conveniently put in the __FILE__ and __LINE__ macros just for debug builds in this function so I can track where VRAM is being allocated? Is there any more elegant way than something like this?: #define CreateRenderTargetTexture(w, h) CreateRenderTargetTexture(w, h, __FILE__, __LINE__) I have a couple of other functions that need this tracking and this way just seems ugly. Any thoughts?

Share this post


Link to post
Share on other sites
You could use StackWalk64() to perform a limited stack walk and store the instruction pointers of the first three or four stack frames. If you need to convert those into file names and lines you can use SymGetLineFromAddr64().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this