From 9e7394afff87634e60e665adc47da798b1e767ac Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Fri, 28 May 2010 16:50:49 +0000 Subject: [PATCH] * Set the PCSX2 event handler queues to use the wxObject allocator (reduces heap fragmentation, multithread performance, etc) [MSW/Win32 only] * SafeFree() macro changed: Remove null check on calls to free(); should be 100% safe as according to wx gurus. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3102 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/include/Utilities/SafeArray.h | 41 +++++++++++---------- common/include/Utilities/wxAppWithHelpers.h | 6 ++- pcsx2/gui/pxEventThread.h | 7 +++- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/common/include/Utilities/SafeArray.h b/common/include/Utilities/SafeArray.h index ca8198c07a..fab95d4ee7 100644 --- a/common/include/Utilities/SafeArray.h +++ b/common/include/Utilities/SafeArray.h @@ -38,12 +38,11 @@ extern void pcsx2_aligned_free(void* pmem); #define safe_delete_array( ptr ) \ ((void) (delete[] (ptr)), (ptr) = NULL) -// fixme: I'm pretty sure modern libc implementations under gcc and msvc check null status -// inside free(), meaning we shouldn't have to do it ourselves. But legacy implementations -// didn't always check, so best to be cautious unless absolutely certain it's being covered on -// all ported platforms. +// No checks for NULL -- wxWidgets says it's safe to skip NULL checks and it runs on +// just about every compiler and libc implementation of any recentness. #define safe_free( ptr ) \ - ((void) (( ( (ptr) != NULL ) && (free( ptr ), !!0) ), (ptr) = NULL)) + ( (void) (free( ptr ), !!0), (ptr) = NULL ) + //((void) (( ( (ptr) != NULL ) && (free( ptr ), !!0) ), (ptr) = NULL)) #define safe_fclose( ptr ) \ ((void) (( ( (ptr) != NULL ) && (fclose( ptr ), !!0) ), (ptr) = NULL)) @@ -86,12 +85,13 @@ protected: // use its own memory allocation (with an aligned memory, for example). // Throws: // Exception::OutOfMemory if the allocated_mem pointer is NULL. - explicit SafeArray( const wxChar* name, T* allocated_mem, int initSize ) : - Name( name ) - , ChunkSize( DefaultChunkSize ) - , m_ptr( allocated_mem ) - , m_size( initSize ) + explicit SafeArray( const wxChar* name, T* allocated_mem, int initSize ) + : Name( name ) { + ChunkSize = DefaultChunkSize; + m_ptr = allocated_mem; + m_size = initSize; + if( m_ptr == NULL ) throw Exception::OutOfMemory(); } @@ -110,20 +110,21 @@ public: safe_free( m_ptr ); } - explicit SafeArray( const wxChar* name=L"Unnamed" ) : - Name( name ) - , ChunkSize( DefaultChunkSize ) - , m_ptr( NULL ) - , m_size( 0 ) + explicit SafeArray( const wxChar* name=L"Unnamed" ) + : Name( name ) { + ChunkSize = DefaultChunkSize; + m_ptr = NULL; + m_size = 0; } - explicit SafeArray( int initialSize, const wxChar* name=L"Unnamed" ) : - Name( name ) - , ChunkSize( DefaultChunkSize ) - , m_ptr( (initialSize==0) ? NULL : (T*)malloc( initialSize * sizeof(T) ) ) - , m_size( initialSize ) + explicit SafeArray( int initialSize, const wxChar* name=L"Unnamed" ) + : Name( name ) { + ChunkSize = DefaultChunkSize; + m_ptr = (initialSize==0) ? NULL : (T*)malloc( initialSize * sizeof(T) ); + m_size = initialSize; + if( (initialSize != 0) && (m_ptr == NULL) ) throw Exception::OutOfMemory(); } diff --git a/common/include/Utilities/wxAppWithHelpers.h b/common/include/Utilities/wxAppWithHelpers.h index 6561ccf361..045ca8735d 100644 --- a/common/include/Utilities/wxAppWithHelpers.h +++ b/common/include/Utilities/wxAppWithHelpers.h @@ -41,7 +41,11 @@ public: virtual void OnActionButtonClicked( wxCommandEvent& evt ); }; -typedef std::list wxEventList; +#ifdef _MSC_VER + typedef std::list< wxEvent*, wxObjectAllocator > wxEventList; +#else + typedef std::list< wxEvent* > wxEventList; +#endif // -------------------------------------------------------------------------------------- // wxAppWithHelpers diff --git a/pcsx2/gui/pxEventThread.h b/pcsx2/gui/pxEventThread.h index 40ad185d40..5aa2b5a9e1 100644 --- a/pcsx2/gui/pxEventThread.h +++ b/pcsx2/gui/pxEventThread.h @@ -126,8 +126,11 @@ protected: } }; - -typedef std::list pxEvtList; +#ifdef _MSC_VER + typedef std::list< SysExecEvent*, wxObjectAllocator > pxEvtList; +#else + typedef std::list pxEvtList; +#endif // -------------------------------------------------------------------------------------- // pxEvtHandler