1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_TOOLS_MEMPOOL_HXX
20 #define INCLUDED_TOOLS_MEMPOOL_HXX
22 #include <sal/config.h>
24 #include <sal/macros.h>
25 #include <tools/toolsdllapi.h>
27 struct FixedMemPool_Impl
;
29 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC FixedMemPool
31 FixedMemPool_Impl
* m_pImpl
;
32 char const * m_pTypeName
;
35 FixedMemPool( char const * pTypeName
,
36 sal_uInt16 nTypeSize
);
43 #define DECL_FIXEDMEMPOOL_NEW_DECL() \
44 static void * operator new( size_t n )
46 #define IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \
48 if ( n == sizeof( Class ) ) \
49 return (aPool).Alloc(); \
51 return ::operator new(n); \
54 #define DECL_FIXEDMEMPOOL_DEL_DECL() \
55 static void operator delete( void * p, size_t n )
57 #define IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool ) \
59 if ( n == sizeof( Class ) ) \
62 ::operator delete(p); \
65 #define DECL_FIXEDMEMPOOL_NEWDEL( Class ) \
67 static FixedMemPool aPool; \
69 DECL_FIXEDMEMPOOL_NEW_DECL() \
70 IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \
71 DECL_FIXEDMEMPOOL_DEL_DECL() \
72 IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool )
74 #define IMPL_FIXEDMEMPOOL_NEWDEL( Class ) \
75 FixedMemPool Class::aPool( SAL_STRINGIFY( Class ), sizeof( Class ) );
77 #define DECL_FIXEDMEMPOOL_NEWDEL_DLL( Class ) \
79 static FixedMemPool aPool; \
81 DECL_FIXEDMEMPOOL_NEW_DECL(); \
82 DECL_FIXEDMEMPOOL_DEL_DECL();
84 #define IMPL_FIXEDMEMPOOL_NEWDEL_DLL( Class ) \
85 FixedMemPool Class::aPool( SAL_STRINGIFY( Class ), sizeof( Class ) ); \
86 void * Class::operator new( size_t n ) \
87 IMPL_FIXEDMEMPOOL_NEW_BODY( Class, aPool ) \
88 void Class::operator delete( void * p, size_t n ) \
89 IMPL_FIXEDMEMPOOL_DEL_BODY( Class, aPool )
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */