2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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.
21 #ifndef WTF_FastMalloc_h
22 #define WTF_FastMalloc_h
30 // These functions call abort() 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);
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);
42 void fastFree(void* p);
44 void* fastMallocExecutable(size_t n);
45 void fastFreeExecutable(void* p);
48 void fastMallocForbid();
49 void fastMallocAllow();
52 void releaseFastMallocFreeMemory();
56 using WTF::fastMalloc;
57 using WTF::fastZeroedMalloc;
58 using WTF::fastCalloc;
59 using WTF::fastRealloc;
60 using WTF::tryFastMalloc;
61 using WTF::tryFastZeroedMalloc;
62 using WTF::tryFastCalloc;
63 using WTF::tryFastRealloc;
67 using WTF::fastMallocForbid;
68 using WTF::fastMallocAllow;
71 #if COMPILER(GCC) && PLATFORM(DARWIN)
72 #define WTF_PRIVATE_INLINE __private_extern__ inline __attribute__((always_inline))
74 #define WTF_PRIVATE_INLINE inline __attribute__((always_inline))
76 #define WTF_PRIVATE_INLINE __forceinline
78 #define WTF_PRIVATE_INLINE inline
81 #ifndef _CRTDBG_MAP_ALLOC
83 #if !defined(USE_SYSTEM_MALLOC) || !(USE_SYSTEM_MALLOC)
84 WTF_PRIVATE_INLINE void* operator new(size_t s) { return fastMalloc(s); }
85 WTF_PRIVATE_INLINE void operator delete(void* p) { fastFree(p); }
86 WTF_PRIVATE_INLINE void* operator new[](size_t s) { return fastMalloc(s); }
87 WTF_PRIVATE_INLINE void operator delete[](void* p) { fastFree(p); }
90 #endif // _CRTDBG_MAP_ALLOC
92 #endif /* WTF_FastMalloc_h */