| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 * | 18 * |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #ifndef WTF_FastMalloc_h | 21 #ifndef WTF_FastMalloc_h |
| 22 #define WTF_FastMalloc_h | 22 #define WTF_FastMalloc_h |
| 23 | 23 |
| 24 #include <wtf/Platform.h> | 24 #include <new> |
| 25 #include <wtf/PossiblyNull.h> | |
| 26 #include <stdlib.h> | 25 #include <stdlib.h> |
| 27 #include <new> | 26 |
| 27 #include "wtf/Platform.h" |
| 28 #include "wtf/PossiblyNull.h" |
| 29 #include "wtf/WTFExport.h" |
| 28 | 30 |
| 29 namespace WTF { | 31 namespace WTF { |
| 30 | 32 |
| 31 // These functions call CRASH() if an allocation fails. | 33 // These functions call CRASH() if an allocation fails. |
| 32 void* fastMalloc(size_t); | 34 WTF_EXPORT void* fastMalloc(size_t); |
| 33 void* fastZeroedMalloc(size_t); | 35 WTF_EXPORT void* fastZeroedMalloc(size_t); |
| 34 void* fastCalloc(size_t numElements, size_t elementSize); | 36 WTF_EXPORT void* fastCalloc(size_t numElements, size_t elementSize); |
| 35 void* fastRealloc(void*, size_t); | 37 WTF_EXPORT void* fastRealloc(void*, size_t); |
| 36 char* fastStrDup(const char*); | 38 WTF_EXPORT char* fastStrDup(const char*); |
| 37 size_t fastMallocSize(const void*); | 39 WTF_EXPORT size_t fastMallocSize(const void*); |
| 38 size_t fastMallocGoodSize(size_t); | 40 WTF_EXPORT size_t fastMallocGoodSize(size_t); |
| 39 | 41 |
| 40 struct TryMallocReturnValue { | 42 struct TryMallocReturnValue { |
| 41 TryMallocReturnValue(void* data) | 43 TryMallocReturnValue(void* data) |
| 42 : m_data(data) | 44 : m_data(data) |
| 43 { | 45 { |
| 44 } | 46 } |
| 45 TryMallocReturnValue(const TryMallocReturnValue& source) | 47 TryMallocReturnValue(const TryMallocReturnValue& source) |
| 46 : m_data(source.m_data) | 48 : m_data(source.m_data) |
| 47 { | 49 { |
| 48 source.m_data = 0; | 50 source.m_data = 0; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 62 template <typename T> bool TryMallocReturnValue::getValue(T& data) | 64 template <typename T> bool TryMallocReturnValue::getValue(T& data) |
| 63 { | 65 { |
| 64 union u { void* data; T target; } res; | 66 union u { void* data; T target; } res; |
| 65 res.data = m_data; | 67 res.data = m_data; |
| 66 data = res.target; | 68 data = res.target; |
| 67 bool returnValue = !!m_data; | 69 bool returnValue = !!m_data; |
| 68 m_data = 0; | 70 m_data = 0; |
| 69 return returnValue; | 71 return returnValue; |
| 70 } | 72 } |
| 71 | 73 |
| 72 TryMallocReturnValue tryFastMalloc(size_t n); | 74 WTF_EXPORT TryMallocReturnValue tryFastMalloc(size_t n); |
| 73 TryMallocReturnValue tryFastZeroedMalloc(size_t n); | 75 WTF_EXPORT TryMallocReturnValue tryFastZeroedMalloc(size_t n); |
| 74 TryMallocReturnValue tryFastCalloc(size_t n_elements, size_t element_size); | 76 WTF_EXPORT TryMallocReturnValue tryFastCalloc(size_t n_elements, size_t elem
ent_size); |
| 75 TryMallocReturnValue tryFastRealloc(void* p, size_t n); | 77 WTF_EXPORT TryMallocReturnValue tryFastRealloc(void* p, size_t n); |
| 76 | 78 |
| 77 void fastFree(void*); | 79 WTF_EXPORT void fastFree(void*); |
| 78 | 80 |
| 79 #ifndef NDEBUG | 81 #ifndef NDEBUG |
| 80 void fastMallocForbid(); | 82 WTF_EXPORT void fastMallocForbid(); |
| 81 void fastMallocAllow(); | 83 WTF_EXPORT void fastMallocAllow(); |
| 82 #endif | 84 #endif |
| 83 | 85 |
| 84 void releaseFastMallocFreeMemory(); | 86 WTF_EXPORT void releaseFastMallocFreeMemory(); |
| 85 | 87 |
| 86 struct FastMallocStatistics { | 88 struct FastMallocStatistics { |
| 87 size_t reservedVMBytes; | 89 size_t reservedVMBytes; |
| 88 size_t committedVMBytes; | 90 size_t committedVMBytes; |
| 89 size_t freeListBytes; | 91 size_t freeListBytes; |
| 90 }; | 92 }; |
| 91 FastMallocStatistics fastMallocStatistics(); | 93 WTF_EXPORT FastMallocStatistics fastMallocStatistics(); |
| 92 | 94 |
| 93 // This defines a type which holds an unsigned integer and is the same | 95 // This defines a type which holds an unsigned integer and is the same |
| 94 // size as the minimally aligned memory allocation. | 96 // size as the minimally aligned memory allocation. |
| 95 typedef unsigned long long AllocAlignmentInteger; | 97 typedef unsigned long long AllocAlignmentInteger; |
| 96 | 98 |
| 97 namespace Internal { | 99 namespace Internal { |
| 98 enum AllocType { // Start with an unusual number inst
ead of zero, because zero is common. | 100 enum AllocType { // Start with an unusual number inst
ead of zero, because zero is common. |
| 99 AllocTypeMalloc = 0x375d6750, // Encompasses fastMalloc, fastZeroe
dMalloc, fastCalloc, fastRealloc. | 101 AllocTypeMalloc = 0x375d6750, // Encompasses fastMalloc, fastZeroe
dMalloc, fastCalloc, fastRealloc. |
| 100 AllocTypeClassNew, // Encompasses class operator new fr
om FastAllocBase. | 102 AllocTypeClassNew, // Encompasses class operator new fr
om FastAllocBase. |
| 101 AllocTypeClassNewArray, // Encompasses class operator new[]
from FastAllocBase. | 103 AllocTypeClassNewArray, // Encompasses class operator new[]
from FastAllocBase. |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 using WTF::tryFastMalloc; | 235 using WTF::tryFastMalloc; |
| 234 using WTF::tryFastRealloc; | 236 using WTF::tryFastRealloc; |
| 235 using WTF::tryFastZeroedMalloc; | 237 using WTF::tryFastZeroedMalloc; |
| 236 | 238 |
| 237 #ifndef NDEBUG | 239 #ifndef NDEBUG |
| 238 using WTF::fastMallocForbid; | 240 using WTF::fastMallocForbid; |
| 239 using WTF::fastMallocAllow; | 241 using WTF::fastMallocAllow; |
| 240 #endif | 242 #endif |
| 241 | 243 |
| 242 #endif /* WTF_FastMalloc_h */ | 244 #endif /* WTF_FastMalloc_h */ |
| OLD | NEW |