1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _SVMEMPOOL_HXX 24 #define _SVMEMPOOL_HXX 25 26 #include "tools/toolsdllapi.h" 27 #include "tools/solar.h" 28 29 // ---------------- 30 // - FixedMemPool - 31 // ---------------- 32 33 struct FixedMemPool_Impl; 34 35 class TOOLS_DLLPUBLIC FixedMemPool 36 { 37 FixedMemPool_Impl * m_pImpl; 38 char const * m_pTypeName; 39 40 public: 41 FixedMemPool( char const * pTypeName, 42 sal_uInt16 nTypeSize, 43 sal_uInt16 nInitSize = 512, 44 sal_uInt16 nGrowSize = 256 ); 45 ~FixedMemPool(); 46 47 void* Alloc(); 48 void Free( void* p ); 49 }; 50 51 // ---------------------------- 52 // - DECL_FIXEDMEMPOOL_NEWDEL - 53 // ---------------------------- 54 55 #define DECL_FIXEDMEMPOOL_NEW_DECL() \ 56 static void * operator new( size_t n ) 57 58 #define DECL_FIXEDMEMPOOL_NEW_IMPL( Class ) \ 59 void * Class::operator new( size_t n ) 60 61 #define IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \ 62 { \ 63 if ( n == sizeof( Class ) ) \ 64 return (aPool).Alloc(); \ 65 else \ 66 return ::operator new(n); \ 67 } 68 69 #define DECL_FIXEDMEMPOOL_NEW_INLINE( Class, aPool ) \ 70 DECL_FIXEDMEMPOOL_NEW_DECL() \ 71 IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) 72 73 #define DECL_FIXEDMEMPOOL_DEL_DECL() \ 74 static void operator delete( void * p, size_t n ) 75 76 #define DECL_FIXEDMEMPOOL_DEL_IMPL( Class ) \ 77 void Class::operator delete( void * p, size_t n ) 78 79 #define IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool ) \ 80 { \ 81 if ( n == sizeof( Class ) ) \ 82 (aPool).Free(p); \ 83 else \ 84 ::operator delete(p); \ 85 } 86 87 #define DECL_FIXEDMEMPOOL_DEL_INLINE( Class, aPool ) \ 88 DECL_FIXEDMEMPOOL_DEL_DECL() \ 89 IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool ) 90 91 #define DECL_FIXEDMEMPOOL_NEWDEL( Class ) \ 92 private: \ 93 static FixedMemPool aPool; \ 94 public: \ 95 DECL_FIXEDMEMPOOL_NEW_INLINE( Class, aPool ) \ 96 DECL_FIXEDMEMPOOL_DEL_INLINE( Class, aPool ) 97 98 #define IMPL_FIXEDMEMPOOL_STRING(x) IMPL_FIXEDMEMPOOL_MAKESTRING(x) 99 #define IMPL_FIXEDMEMPOOL_MAKESTRING(x) #x 100 101 #define IMPL_FIXEDMEMPOOL_NEWDEL( Class, InitSize, GrowSize) \ 102 FixedMemPool Class::aPool( IMPL_FIXEDMEMPOOL_STRING( Class ), sizeof( Class ), (InitSize), (GrowSize) ); 103 104 #define DECL_FIXEDMEMPOOL_NEWDEL_DLL( Class ) \ 105 private: \ 106 static FixedMemPool aPool; \ 107 public: \ 108 DECL_FIXEDMEMPOOL_NEW_DECL(); \ 109 DECL_FIXEDMEMPOOL_DEL_DECL(); 110 111 #define IMPL_FIXEDMEMPOOL_NEWDEL_DLL( Class, InitSize, GrowSize) \ 112 FixedMemPool Class::aPool( IMPL_FIXEDMEMPOOL_STRING( Class ), sizeof( Class ), (InitSize), (GrowSize) ); \ 113 DECL_FIXEDMEMPOOL_NEW_IMPL( Class ) \ 114 IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \ 115 DECL_FIXEDMEMPOOL_DEL_IMPL( Class ) \ 116 IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool ) 117 118 #define INIT_FIXEDMEMPOOL_NEWDEL_DLL( Class, aPool, InitSize, GrowSize ) \ 119 aPool( IMPL_FIXEDMEMPOOL_STRING( Class ), sizeof( Class ), (InitSize), (GrowSize) ) 120 121 #endif // _SVMEMPOOL_HXX 122