]>
Commit | Line | Data |
---|---|---|
b37bf2e1 | 1 | /* |
f4e78d34 | 2 | * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
b37bf2e1 A |
3 | * |
4 | * This library is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU Library General Public | |
6 | * License as published by the Free Software Foundation; either | |
7 | * version 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * This library is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * Library General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU Library General Public License | |
15 | * along with this library; see the file COPYING.LIB. If not, write to | |
16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
17 | * Boston, MA 02110-1301, USA. | |
18 | * | |
19 | */ | |
20 | ||
21 | #ifndef WTF_FastMalloc_h | |
22 | #define WTF_FastMalloc_h | |
23 | ||
24 | #include "Platform.h" | |
25 | #include <stdlib.h> | |
26 | #include <new> | |
27 | ||
28 | namespace WTF { | |
29 | ||
9dae56ea A |
30 | // These functions call CRASH() if an allocation fails. |
31 | void* fastMalloc(size_t n); | |
32 | void* fastZeroedMalloc(size_t n); | |
33 | void* fastCalloc(size_t n_elements, size_t element_size); | |
34 | void* fastRealloc(void* p, size_t n); | |
35 | ||
36 | // These functions return NULL if an allocation fails. | |
37 | void* tryFastMalloc(size_t n); | |
38 | void* tryFastZeroedMalloc(size_t n); | |
39 | void* tryFastCalloc(size_t n_elements, size_t element_size); | |
40 | void* tryFastRealloc(void* p, size_t n); | |
41 | ||
b37bf2e1 | 42 | void fastFree(void* p); |
b37bf2e1 A |
43 | |
44 | #ifndef NDEBUG | |
45 | void fastMallocForbid(); | |
46 | void fastMallocAllow(); | |
47 | #endif | |
48 | ||
f4e78d34 | 49 | void releaseFastMallocFreeMemory(); |
9dae56ea A |
50 | |
51 | struct FastMallocStatistics { | |
52 | size_t heapSize; | |
53 | size_t freeSizeInHeap; | |
54 | size_t freeSizeInCaches; | |
55 | size_t returnedSize; | |
56 | }; | |
57 | FastMallocStatistics fastMallocStatistics(); | |
f4e78d34 | 58 | |
b37bf2e1 A |
59 | } // namespace WTF |
60 | ||
61 | using WTF::fastMalloc; | |
62 | using WTF::fastZeroedMalloc; | |
63 | using WTF::fastCalloc; | |
64 | using WTF::fastRealloc; | |
9dae56ea A |
65 | using WTF::tryFastMalloc; |
66 | using WTF::tryFastZeroedMalloc; | |
67 | using WTF::tryFastCalloc; | |
68 | using WTF::tryFastRealloc; | |
b37bf2e1 A |
69 | using WTF::fastFree; |
70 | ||
71 | #ifndef NDEBUG | |
72 | using WTF::fastMallocForbid; | |
73 | using WTF::fastMallocAllow; | |
74 | #endif | |
75 | ||
76 | #if COMPILER(GCC) && PLATFORM(DARWIN) | |
77 | #define WTF_PRIVATE_INLINE __private_extern__ inline __attribute__((always_inline)) | |
78 | #elif COMPILER(GCC) | |
79 | #define WTF_PRIVATE_INLINE inline __attribute__((always_inline)) | |
80 | #elif COMPILER(MSVC) | |
81 | #define WTF_PRIVATE_INLINE __forceinline | |
82 | #else | |
83 | #define WTF_PRIVATE_INLINE inline | |
84 | #endif | |
85 | ||
86 | #ifndef _CRTDBG_MAP_ALLOC | |
87 | ||
88 | #if !defined(USE_SYSTEM_MALLOC) || !(USE_SYSTEM_MALLOC) | |
89 | WTF_PRIVATE_INLINE void* operator new(size_t s) { return fastMalloc(s); } | |
90 | WTF_PRIVATE_INLINE void operator delete(void* p) { fastFree(p); } | |
91 | WTF_PRIVATE_INLINE void* operator new[](size_t s) { return fastMalloc(s); } | |
92 | WTF_PRIVATE_INLINE void operator delete[](void* p) { fastFree(p); } | |
b37bf2e1 A |
93 | #endif |
94 | ||
95 | #endif // _CRTDBG_MAP_ALLOC | |
96 | ||
97 | #endif /* WTF_FastMalloc_h */ |