File & Line macros in member function

Started by
0 comments, last by SiCrane 15 years, 3 months ago
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?
Construct (Free open-source game creator)
Advertisement
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().

This topic is closed to new replies.

Advertisement