[Vortex] Windows issues and memory tracking in debug builds
Yourch, Chris
chris at replicus.com
Thu Nov 8 19:57:53 CET 2007
1. The source code downloaded from Sourceforge does not include the
libaxl.def. Also, the libaxl.vcproj file does not include the .DEF file
either.
2. Oh, I was thinking this was a private API call. At least in debug
builds, using the memory tracking suggestions below, a free on an object
already freed would be caught.
As for the memory tracking changes, I can make them here and send you
the updated modules?
Chris
-----Original Message-----
From: Francis Brosnan Blazquez [mailto:francis at aspl.es]
Sent: Thursday, November 08, 2007 12:41 AM
To: Yourch, Chris
Cc: Vortex
Subject: Re: Windows issues and memory tracking in debug builds
Hi Chris,
> Here's a bunch of issues and suggestions related to the Windows/Visual
> Studio environment:
>
>
> 1. The libaxl project is missing a .DEF file so it only compiles as a
> static library for now.
The windows installer includes the libaxl.def file and the libaxl.lib at
the lib/ directory, and the source code includes the libaxl.def inside
the src/ directory. Let me know if there is something missing.
> 2. Suggestion: Instead of "vortex_frame_unref(VortexFrame * frame)"
how
> about "vortex_frame_unref(VortexFrame ** frame)" so that when the ref
> count goes to 0 and the frame is freed you can set the frame pointer
to
> NULL.
This looks good, but looks as a hard API change. What about adding
something like vortex_frame_unref_nullify (VortexFrame ** frame), which
would coexists with vortex_frame_unref?
> 3. Tracking memory allocations: For debug builds, define
> _CRTDBG_MAP_ALLOC in the libvortex and libaxl Visual Studio projects
> under the Properties -> C/C++ -> preprocessor section.
>
>
> 4. Turning on more aggressive allocation/free checking: At line 44 of
> vortex_win32.c add the following:
>
> #ifdef _DEBUG
> #include <crtdbg.h>
> #endif
>
> And, in the same module, add this to the first line of DllMain():
> #ifdef _DEBUG
> _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_CHECK_ALWAYS_DF|
> _CRTDBG_CHECK_CRT_DF|_CRTDBG_DELAY_FREE_MEM_DF|
> _CRTDBG_LEAK_CHECK_DF);
> #endif
>
>
> 5. Further memory tracking: To track allocations and frees for Vortex
> specific objects during _DEBUG builds have axl_new() call
_calloc_dbg()
> and axl_free() call _free_dbg(). The debug versions of these functions
> have additional parameters. They take a blocktype value (an int), the
> filename and the linenumber. The blocktype is an important field. For
> each specific Vortex "type" define a sub-blocktype number that is
OR'ed
> with the blocktype.
>
> // Define the memory block sub-type for Vortex types:
> enum MicrosoftMemoryBlockTypes
> {
> BLKTYPE_VortexChannelData = 1, // VortexChannelData:
> BLKTYPE_char, // char:
> BLKTYPE_VortexChannel // VortexChannel
>
> // and so on...
> };
>
> // Update the signature of axl_new():
> #ifdef _DEBUG
> #define axl_new(type, count, blksubtype) \
> (type *) _calloc_dbg(count, sizeof(type), \
> (_CLIENT_BLOCK | ((blksubtype) << 16)), \
> __FILE__, __LINE__)
> #else
> #define axl_new(type, count) (type *) calloc (count, sizeof
(type))
> #endif
>
> // Update the signature of axl_free():
> #ifdef _DEBUG
> #define axl_free(ptr, blksubtype) \
> _free_dbg(ptr, (_CLIENT_BLOCK | ((blksubtype) << 16))
> #else
> #define axl_free(ptr) free(ptr)
> #endif
>
>
> Finally, when leaks are detected or the memory needs to be dumped, the
> Vortex specific dump function will be called. This is defined as
> follows:
>
> #ifdef _DEBUG
> void __cdecl DumpVortexObjectFunction(void *pUserData, size_t nBytes)
> {
> int blktype = _CrtReportBlockType(pUserData);
> int blksubtype = ((blktype >> 16) & 0xFFFF);
>
> if (blksubtype == BLKTYPE_VortexChannelData)
> {
> VortexChannelData *channelData = (VortexChannelData *)pUserData;
>
> _RPT2(_CRT_WARN, "VortexChannelData: host=%s, channel_num = %d\n",
> vortex_connection_get_host(channelData->connection),
> channelData->channel_num);
>
> _ASSERTE(channelData->connection != NULL);
> }
> else if (blksubtype == BLKTYPE_VortexChannel)
> {
> VortexChannel *channel = (VortexChannel *)pUserData;
>
> _RPT3(_CRT_WARN, "VortexChannel: host=%s, port=%s, channel_num =
> %d\n",
> vortex_connection_get_host(channel->connection),
> vortex_connection_get_port(channel->connection),
> channelData->channel_num);
>
> _ASSERTE(channel->connection != NULL);
> _ASSERTE(channel->profile != NULL);
> }
>
> // And so on....
>
> }
> #endif
>
> To install the dump function call this method as follows:
> #ifdef _DEBUG
> _CrtSetDumpClient(DumpVortexObjectFunction);
> #endif
> This call would be placed as the 2nd line of DllMain().
>
>
>
>
> Making the above changes will really help to ensure a solid Windows
> version of the Vortex library.
>
> Thanks for listening!
Thanks for the suggestions Chris,
Cheers!
> Best Regards,
>
> Chris Yourch
>
>
>
>
--
Francis Brosnan Blazquez <francis at aspl.es>
Advanced Software Production Line, S.L.
More information about the Vortex
mailing list