From 2b7331b73bb17e4134382a9398579ed3b6795dab Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 20 Jul 2002 21:37:10 +0000 Subject: [PATCH] Added some extra checks for memory initialization into the osg::MemoryManager, this is turned off by default, even in debug build. However you can turn it on by setting the OSG_MM_CHECK_FOR_UNINITIALIZED --- src/osg/MemoryManager.cpp | 57 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/osg/MemoryManager.cpp b/src/osg/MemoryManager.cpp index 431cbb32f..1c54455a2 100644 --- a/src/osg/MemoryManager.cpp +++ b/src/osg/MemoryManager.cpp @@ -159,6 +159,7 @@ sMStats m_getMemoryStatistics() static bool alwaysValidateAll = true; static bool alwaysLogAll = true; static bool alwaysWipeAll = true; + static bool checkForUnitialized = true; static bool cleanupLogOnFirstRun = true; static const unsigned int paddingSize = 1024; // An extra 8K per allocation! #else @@ -167,6 +168,7 @@ sMStats m_getMemoryStatistics() static bool alwaysValidateAll = false; static bool alwaysLogAll = false; static bool alwaysWipeAll = true; + static bool checkForUnitialized = false; static bool cleanupLogOnFirstRun = true; static const unsigned int paddingSize = 4; #endif @@ -242,7 +244,10 @@ sMStats m_getMemoryStatistics() char *ptr; if( (ptr = getenv("OSG_MM_STRESS_TEST")) != 0) { - activateStressTest(); + if (strcmp(ptr,"OFF")!=0) + { + activateStressTest(); + } } if( (ptr = getenv("OSG_MM_BREAK_ON_ALLOCATION")) != 0) @@ -254,6 +259,13 @@ sMStats m_getMemoryStatistics() } } + if( (ptr = getenv("OSG_MM_CHECK_FOR_UNINITIALIZED")) != 0) + { + if (strcmp(ptr,"OFF")!=0) + { + checkForUnitialized=true; + } + } } @@ -452,6 +464,42 @@ sMStats m_getMemoryStatistics() } } + static bool checkPattern(sAllocUnit *allocUnit, unsigned long pattern=unusedPattern) + { + int numMatching=0; + int numNotMatching=0; + + + long *lptr = (long *) ((char *)allocUnit->reportedAddress); + int length = allocUnit->reportedSize; + int i; + for (i = 0; i < (length >> 2); i++, lptr++) + { + if (*lptr == pattern) numMatching+=4; + else numNotMatching+=4; + } + + // Fill the remainder + + unsigned int shiftCount = 0; + char *cptr = (char *) lptr; + for (i = 0; i < (length & 0x3); i++, cptr++, shiftCount += 8) + { + if (*cptr == static_cast((pattern >> shiftCount) & 0xff)) ++numMatching; + else ++numNotMatching; + } + + if (numMatching>0) + { + // possible unitialized data? + std::cout<<"possible uninitilized memory numMatching="<sourceFile<<"' sourceLine="<sourceLine<next; } }