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);
45 void fastMallocForbid();
46 void fastMallocAllow();
49 void releaseFastMallocFreeMemory();
53 using WTF::fastMalloc;
54 using WTF::fastZeroedMalloc;
55 using WTF::fastCalloc;
56 using WTF::fastRealloc;
57 using WTF::tryFastMalloc;
58 using WTF::tryFastZeroedMalloc;
59 using WTF::tryFastCalloc;
60 using WTF::tryFastRealloc;
64 using WTF::fastMallocForbid;
65 using WTF::fastMallocAllow;
68 #if COMPILER(GCC) && PLATFORM(DARWIN)
69 #define WTF_PRIVATE_INLINE __private_extern__ inline __attribute__((always_inline))
71 #define WTF_PRIVATE_INLINE inline __attribute__((always_inline))
73 #define WTF_PRIVATE_INLINE __forceinline
75 #define WTF_PRIVATE_INLINE inline
78 #ifndef _CRTDBG_MAP_ALLOC
80 #if !defined(USE_SYSTEM_MALLOC) || !(USE_SYSTEM_MALLOC)
81 WTF_PRIVATE_INLINE void* operator new(size_t s) { return fastMalloc(s); }
82 WTF_PRIVATE_INLINE void operator delete(void* p) { fastFree(p); }
83 WTF_PRIVATE_INLINE void* operator new[](size_t s) { return fastMalloc(s); }
84 WTF_PRIVATE_INLINE void operator delete[](void* p) { fastFree(p); }
87 #endif // _CRTDBG_MAP_ALLOC
89 #endif /* WTF_FastMalloc_h */