NCBI C++ ToolKit
ncbimempool.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CORELIB___NCBIMEMPOOL__HPP
2 #define CORELIB___NCBIMEMPOOL__HPP
3 
4 /* $Id: ncbimempool.hpp 33815 2007-05-04 17:18:18Z kazimird $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author: Eugene Vasilchenko
30  *
31  *
32  */
33 
34 /// @file ncbimempool.hpp
35 /// Memory pool for fast allocation of memory for localized set of CObjects,
36 /// e.g. when deserializing big object tree.
37 
38 
39 #include <corelib/ncbistd.hpp>
40 #include <corelib/ncbiobj.hpp>
41 
42 
43 /** @addtogroup Object
44  *
45  * @{
46  */
47 
48 
49 
51 
53 
55 {
56 public:
57  /// constructor
58  /// @param chunk_size
59  /// Size of chunks to allocate from system heap.
60  /// If it's zero, use some default size.
61  CObjectMemoryPool(size_t chunk_size = 0);
62  /// destructor
63  ~CObjectMemoryPool(void);
64 
65  /// configurable parameters
66 
67  /// Get chunks' size.
68  size_t GetChunkSize(void) const;
69 
70  /// Change chunks' size.
71  /// @param chunk_size
72  /// Size of chunks to allocate from system heap.
73  /// If it's zero, use some default size.
74  void SetChunkSize(size_t chunk_size);
75 
76  /// Get threshold for direct allocation from system heap.
77  size_t GetMallocThreshold(void) const;
78 
79  /// Change threshold for direct allocation from system heap.
80  /// @param malloc_threshold
81  /// Objects with size greater than this value will be allocated
82  /// directly from system heap.
83  /// If it's zero, use some default threshold.
84  void SetMallocThreshold(size_t malloc_threshold);
85 
86  /// Allocate memory block.
87  void* Allocate(size_t size);
88 
89  /// Deallocate memory block.
90  /// Deallocated momory is not reused, but block counter is decremented,
91  /// and if it goes to zero, full memory chunk is freed.
92  void Deallocate(void* ptr);
93 
94  /// Check if object is allocated from some memory pool,
95  /// and delete it correspondingly.
96  static void Delete(const CObject* object);
97 
98 private:
99  size_t m_ChunkSize;
102 
103 private:
104  // prevent copying
107 };
108 
109 
110 ////////////////////////////////////////////////////////////////////////////
111 // inline functions
112 
113 inline
115 {
116  return m_ChunkSize;
117 }
118 
119 
120 inline
122 {
123  return m_MallocThreshold;
124 }
125 
126 
128 
129 /* @} */
130 
131 #endif /* CORELIB___NCBIMEMPOOL__HPP */
CObject –.
Definition: ncbiobj.hpp:180
static const int chunk_size
Include a standard set of the NCBI C++ Toolkit most basic headers.
CObjectMemoryPool(const CObjectMemoryPool &)
friend class CObjectMemoryPool
Definition: ncbiobj.hpp:359
size_t GetChunkSize(void) const
configurable parameters
void operator=(const CObjectMemoryPool &)
CRef< CObjectMemoryPoolChunk > m_CurrentChunk
size_t GetMallocThreshold(void) const
Get threshold for direct allocation from system heap.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_XNCBI_EXPORT
Definition: ncbi_export.h:1283
const struct ncbi::grid::netcache::search::fields::SIZE size
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Modified on Sat Dec 09 04:47:33 2023 by modify_doxy.py rev. 669887