xref: /trunk/main/tools/source/memtools/mempool.cxx (revision 79aad27f)
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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_tools.hxx"
26 
27 #include "tools/mempool.hxx"
28 #include "osl/diagnose.h"
29 #include "rtl/alloc.h"
30 
31 #ifndef INCLUDED_STDIO_H
32 #include <stdio.h>
33 #endif
34 
35 /*************************************************************************
36 |*
37 |*    FixedMemPool::FixedMemPool()
38 |*
39 *************************************************************************/
40 
FixedMemPool(char const * pTypeName,sal_uInt16 nTypeSize,sal_uInt16,sal_uInt16)41 FixedMemPool::FixedMemPool (
42 	char const * pTypeName, sal_uInt16 nTypeSize, sal_uInt16, sal_uInt16)
43   : m_pTypeName (pTypeName)
44 {
45 	char name[RTL_CACHE_NAME_LENGTH + 1];
46 	snprintf (name, sizeof(name), "FixedMemPool_%d", (int)nTypeSize);
47 	m_pImpl = (FixedMemPool_Impl*)rtl_cache_create (name, nTypeSize, 0, NULL, NULL, NULL, 0, NULL, 0);
48     OSL_TRACE("FixedMemPool::ctor(\"%s\"): %p", m_pTypeName, m_pImpl);
49 }
50 
51 /*************************************************************************
52 |*
53 |*    FixedMemPool::~FixedMemPool()
54 |*
55 *************************************************************************/
56 
~FixedMemPool()57 FixedMemPool::~FixedMemPool()
58 {
59     OSL_TRACE("FixedMemPool::dtor(\"%s\"): %p", m_pTypeName, m_pImpl);
60     rtl_cache_destroy ((rtl_cache_type*)(m_pImpl)), m_pImpl = 0;
61 }
62 
63 /*************************************************************************
64 |*
65 |*    FixedMemPool::Alloc()
66 |*
67 *************************************************************************/
68 
Alloc()69 void* FixedMemPool::Alloc()
70 {
71 	return rtl_cache_alloc ((rtl_cache_type*)(m_pImpl));
72 }
73 
74 /*************************************************************************
75 |*
76 |*    FixedMemPool::Free()
77 |*
78 *************************************************************************/
79 
Free(void * pFree)80 void FixedMemPool::Free( void* pFree )
81 {
82 	rtl_cache_free ((rtl_cache_type*)(m_pImpl), pFree);
83 }
84