From ca49f2edc0c2c26b043636c0ab92b258f2d1f289 Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Thu, 8 Oct 2009 23:23:35 +0000 Subject: [PATCH] wxWidgets/Win32: Helps when I include the necessary files (HeapAllocator.cpp / HeapAllocator.h) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1989 96395faa-99c1-11dd-bbfe-3dabce05a288 --- .../wxWidgets/include/wx/msw/HeapAllocator.h | 164 ++++++++++++++++++ 3rdparty/wxWidgets/src/msw/HeapAllocator.cpp | 76 ++++++++ 2 files changed, 240 insertions(+) create mode 100644 3rdparty/wxWidgets/include/wx/msw/HeapAllocator.h create mode 100644 3rdparty/wxWidgets/src/msw/HeapAllocator.cpp diff --git a/3rdparty/wxWidgets/include/wx/msw/HeapAllocator.h b/3rdparty/wxWidgets/include/wx/msw/HeapAllocator.h new file mode 100644 index 0000000000..a47b51ae4d --- /dev/null +++ b/3rdparty/wxWidgets/include/wx/msw/HeapAllocator.h @@ -0,0 +1,164 @@ +#pragma once + +#include + +extern void _allocateHeap_wxString(); +extern void _destroyHeap_wxString(); +extern void* _allocHeap_wxString( size_t size ); +extern void _freeHeap_wxString( void* ptr ); + +extern void _allocateHeap_wxObject(); +extern void _destroyHeap_wxObject(); +extern void* _allocHeap_wxObject( size_t size ); +extern void _freeHeap_wxObject( void* ptr ); + +template +class wxStringAllocator +{ +public : + // typedefs + + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + +public : + // convert an allocator to allocator + + template + struct rebind { + typedef wxStringAllocator other; + }; + +public : + wxStringAllocator() + { + _allocateHeap_wxString(); + } + + ~wxStringAllocator() + { + _destroyHeap_wxString(); + } + + wxStringAllocator(wxStringAllocator const&) {} + + template + explicit wxStringAllocator(wxStringAllocator const&) {} + + // address + + pointer address(reference r) { return &r; } + const_pointer address(const_reference r) { return &r; } + + // memory allocation + + pointer allocate(size_type cnt, + typename std::allocator::const_pointer = 0) + { + return reinterpret_cast( _allocHeap_wxString(cnt * sizeof(T)) ); + } + + void deallocate(pointer p, size_type) + { + _freeHeap_wxString( p ); + } + + // size + + size_type max_size() const { + return std::numeric_limits::max() / sizeof(T); + } + + // construction/destruction + + // standard placement-new syntax to initialize the object: + void construct(pointer p, const T& t) { new(p) T(t); } + // standard placement destructor: + void destroy(pointer p) { p->~T(); } + + bool operator==(wxStringAllocator const&) { return true; } + bool operator!=(wxStringAllocator const& a) { return !operator==(a); } +}; // end of class Allocator + + +// -------------------------------------------------------------------------------------- +// +// -------------------------------------------------------------------------------------- +template +class wxObjectAllocator +{ +public : + // typedefs + + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + +public : + // convert an allocator to allocator + + template + struct rebind { + typedef wxObjectAllocator other; + }; + +public : + wxObjectAllocator() + { + _allocateHeap_wxObject(); + } + + ~wxObjectAllocator() + { + _destroyHeap_wxObject(); + } + + wxObjectAllocator(wxObjectAllocator const&) {} + + template + explicit wxObjectAllocator(wxObjectAllocator const&) {} + + // address + + pointer address(reference r) { return &r; } + const_pointer address(const_reference r) { return &r; } + + // memory allocation + + pointer allocate(size_type cnt, + typename std::allocator::const_pointer = 0) + { + return reinterpret_cast( _allocHeap_wxObject(cnt * sizeof(T)) ); + } + + void deallocate(pointer p, size_type) + { + _freeHeap_wxObject( p ); + } + + // size + + size_type max_size() const { + return std::numeric_limits::max() / sizeof(T); + } + + // construction/destruction + + // standard placement-new syntax to initialize the object: + void construct(pointer p, const T& t) { new(p) T(t); } + // standard placement destructor: + void destroy(pointer p) { p->~T(); } + + bool operator==(wxObjectAllocator const&) { return true; } + bool operator!=(wxObjectAllocator const& a) { return !operator==(a); } +}; // end of class Allocator + diff --git a/3rdparty/wxWidgets/src/msw/HeapAllocator.cpp b/3rdparty/wxWidgets/src/msw/HeapAllocator.cpp new file mode 100644 index 0000000000..04c5c8c1f9 --- /dev/null +++ b/3rdparty/wxWidgets/src/msw/HeapAllocator.cpp @@ -0,0 +1,76 @@ +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/intl.h" + #include "wx/thread.h" +#endif + +#include + +#ifndef __WXWINCE__ + #include +#endif + +#include +#include + +static HANDLE win32_string_heap = INVALID_HANDLE_VALUE; +static int win32_string_heap_refcount; + +static HANDLE win32_object_heap = INVALID_HANDLE_VALUE; +static int win32_object_heap_refcount; + +void _allocateHeap_wxString() +{ + if( win32_string_heap == INVALID_HANDLE_VALUE ) + { + //wxASSERT( win32_string_heap_refcount == 0 ); + win32_string_heap = HeapCreate( HEAP_NO_SERIALIZE, 0x200000, 0 ); + } +} + +void _destroyHeap_wxString() +{ + if( win32_string_heap == INVALID_HANDLE_VALUE ) return; +} + +void* _allocHeap_wxString( size_t size ) +{ + return (void*)HeapAlloc( win32_string_heap, 0, size ); +} + +void _freeHeap_wxString( void* ptr ) +{ + HeapFree( win32_string_heap, 0, ptr ); +} + + +void _allocateHeap_wxObject() +{ + if( win32_object_heap == INVALID_HANDLE_VALUE ) + { + //wxASSERT( win32_object_heap_refcount == 0 ); + win32_object_heap = HeapCreate( HEAP_NO_SERIALIZE, 0x200000, 0 ); + } +} + +void _destroyHeap_wxObject() +{ + if( win32_object_heap == INVALID_HANDLE_VALUE ) return; +} + +void* _allocHeap_wxObject( size_t size ) +{ + return (void*)HeapAlloc( win32_object_heap, 0, size ); +} + +void _freeHeap_wxObject( void* ptr ) +{ + HeapFree( win32_object_heap, 0, ptr ); +}