Friday, June 22, 2007

It is easy to use templates, but it is hard to make them

Yes this is the template nightmare when you use it and link it to your code. Just take a look at some template libraries that we use in our everyday programming, like STL, ATL, WTL, some libraries from Boost, and you will see what I mean by this. Those libraries are great example of the principle "simple interface - complex implementation".

After hours and days finding the errors without result, I found the interesting topic here http://support.microsoft.com/kb/168958 and here http://www.unknownroad.com/rtfm/VisualStudio/warningC4251.html.

This what was happened to me. I've created a DLL from a class of mine where i use std::vector<> members to store something. My problem is that when i call a library function that insert an element on the vector, the first operation after that one on the vector (clear it, read the first element,etc) cause an error on the heap:

Expression: _CrtIsValidHeapPointer(pUserData)
HEAP[Print.exe]: Invalid Address specified to RtlValidateHeap( 28d0000, 28e3bd0 )

Gosh, it took me days to find what the cause. Trying this trying that, use this best practice that best practice closure but none worked. Very wasting time.

No comments: