7fd59977 |
1 | // File: NCollection_BaseAllocator.hxx |
2 | // Created: Fri Apr 12 09:22:55 2002 |
3 | // Author: Alexander KARTOMIN (akm) |
4 | // <a-kartomin@opencascade.com> |
5 | // |
6 | // Purpose: Basic class for memory allocation wizards. |
7 | // Defines the interface for devising different allocators |
8 | // firstly to be used by collections of NCollection, though it |
9 | // it is not deferred. It allocates/frees the memory through |
10 | // Standard procedures, thus it is unnecessary (and sometimes |
11 | // injurious) to have more than one such allocator. To avoid |
12 | // creation of multiple objects the constructors were maid |
13 | // inaccessible. To create the BaseAllocator use the method |
14 | // CommonBaseAllocator. |
15 | // Note that this object is managed by Handle. |
16 | // |
17 | |
18 | #ifndef NCollection_BaseAllocator_HeaderFile |
19 | #define NCollection_BaseAllocator_HeaderFile |
20 | |
21 | #include <MMgt_TShared.hxx> |
22 | #include <Standard_DefineHandle.hxx> |
23 | #include <NCollection_TypeDef.hxx> |
24 | |
25 | class Handle(NCollection_BaseAllocator); |
26 | |
27 | /** |
28 | * Purpose: Basic class for memory allocation wizards. |
29 | * Defines the interface for devising different allocators |
30 | * firstly to be used by collections of NCollection, though it |
31 | * it is not deferred. It allocates/frees the memory through |
32 | * Standard procedures, thus it is unnecessary (and sometimes |
33 | * injurious) to have more than one such allocator. To avoid |
34 | * creation of multiple objects the constructors were maid |
35 | * inaccessible. To create the BaseAllocator use the method |
36 | * CommonBaseAllocator. |
37 | * Note that this object is managed by Handle. |
38 | */ |
39 | class NCollection_BaseAllocator : public MMgt_TShared |
40 | { |
41 | public: |
42 | // ---------- PUBLIC METHODS ------------ |
43 | Standard_EXPORT virtual void* Allocate (const size_t size); |
44 | Standard_EXPORT virtual void Free (void * anAddress); |
45 | |
46 | //! CommonBaseAllocator |
47 | //! This method is designed to have the only one BaseAllocator (to avoid |
48 | //! useless copying of collections). However one can use operator new to |
49 | //! create more BaseAllocators, but it is injurious. |
50 | Standard_EXPORT static const Handle(NCollection_BaseAllocator)& |
51 | CommonBaseAllocator(void); |
52 | |
53 | //! Callback function to register alloc/free calls |
54 | Standard_EXPORT static void StandardCallBack |
55 | (const Standard_Boolean theIsAlloc, |
56 | const Standard_Address theStorage, |
57 | const Standard_Size theRoundSize, |
58 | const Standard_Size theSize); |
59 | |
60 | //! Prints memory usage statistics cumulated by StandardCallBack |
61 | Standard_EXPORT static void PrintMemUsageStatistics(); |
62 | |
63 | protected: |
64 | //! Constructor - prohibited |
65 | NCollection_BaseAllocator(void) {}; |
66 | |
67 | private: |
68 | //! Copy constructor - prohibited |
69 | NCollection_BaseAllocator(const NCollection_BaseAllocator&); |
70 | |
71 | public: |
72 | // ---------- CasCade RunTime Type Information |
73 | DEFINE_STANDARD_RTTI(NCollection_BaseAllocator) |
74 | }; |
75 | |
76 | DEFINE_STANDARD_HANDLE(NCollection_BaseAllocator,MMgt_TShared) |
77 | |
78 | #endif |