/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/HeapAllocator.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/HeapAllocator.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 11 months ago) by william
File size: 3020 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 // HeapAllocator.cpp
2 //
3 // Copyright 2009-2010 by the PCSX Dev Team.
4 // (under whatever license is appropriate for this sort of hack, I guess).
5 //
6 // Provides a specialized heap for wxStrings, which helps keep the main heap from being
7 // excessively fragmented/cluttered by billions of micro-sized string allocations. This
8 // should also improve multithreaded performace since strings can be allocated in parallel
9 // with other "common" allocation tasks on other threads.
10 //
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/string.h"
21 #include "wx/intl.h"
22 #include "wx/thread.h"
23 #endif
24
25 #include <ctype.h>
26
27 #ifndef __WXWINCE__
28 #include <errno.h>
29 #endif
30
31 #include <string.h>
32 #include <stdlib.h>
33
34 static HANDLE win32_string_heap = INVALID_HANDLE_VALUE;
35 static int win32_string_heap_refcount;
36
37 static HANDLE win32_object_heap = INVALID_HANDLE_VALUE;
38 static int win32_object_heap_refcount;
39
40 void _createHeap_wxString()
41 {
42 if( win32_string_heap == INVALID_HANDLE_VALUE )
43 {
44 //wxASSERT( win32_string_heap_refcount == 0 );
45 win32_string_heap = HeapCreate( 0, 0x200000, 0 );
46 }
47 }
48
49 void _destroyHeap_wxString()
50 {
51 if( win32_string_heap == INVALID_HANDLE_VALUE ) return;
52 }
53
54 void* _allocHeap_wxString( size_t size )
55 {
56 return (void*)HeapAlloc( win32_string_heap, 0, size );
57 }
58
59 void* _reallocHeap_wxString( void* original, size_t size )
60 {
61 if( !original )
62 return _allocHeap_wxString( size );
63 else
64 return (void*)HeapReAlloc( win32_string_heap, 0, original, size );
65 }
66
67 void _freeHeap_wxString( void* ptr )
68 {
69 HeapFree( win32_string_heap, 0, ptr );
70 }
71
72
73 char* _mswHeap_Strdup( const char* src )
74 {
75 if( !src ) return NULL;
76 const size_t len = strlen(src);
77 char* retval = (char*)_allocHeap_wxString( len+1 );
78 if( !retval ) return NULL;
79 memcpy( retval, src, len+1 );
80 return retval;
81 }
82
83 wchar_t* _mswHeap_Strdup( const wchar_t* src )
84 {
85 if( !src ) return NULL;
86 const size_t len = (wcslen(src) + 1) * sizeof(wchar_t);
87 wchar_t* retval = (wchar_t*)_allocHeap_wxString( len );
88 if( !retval ) return NULL;
89 memcpy( retval, src, len );
90 return retval;
91 }
92
93 // --------------------------------------------------------------------------------------
94 //
95 // --------------------------------------------------------------------------------------
96
97 void _createHeap_wxObject()
98 {
99 if( win32_object_heap == INVALID_HANDLE_VALUE )
100 {
101 //wxASSERT( win32_object_heap_refcount == 0 );
102 win32_object_heap = HeapCreate( 0, 0x200000, 0 );
103 }
104 }
105
106 void _destroyHeap_wxObject()
107 {
108 if( win32_object_heap == INVALID_HANDLE_VALUE ) return;
109 }
110
111 void* _allocHeap_wxObject( size_t size )
112 {
113 return (void*)HeapAlloc( win32_object_heap, 0, size );
114 }
115
116 void* _reallocHeap_wxObject( void* original, size_t size )
117 {
118 if( !original )
119 return _allocHeap_wxObject( size );
120 else
121 return (void*)HeapReAlloc( win32_object_heap, 0, original, size );
122 }
123
124 void _freeHeap_wxObject( void* ptr )
125 {
126 HeapFree( win32_object_heap, 0, ptr );
127 }

  ViewVC Help
Powered by ViewVC 1.1.22