HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SmallObject.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SmallObject.h ( UT Library, C++)
7  *
8  * COMMENTS: Small object allocator.
9  */
10 
11 #ifndef __UT_SmallObject__
12 #define __UT_SmallObject__
13 
15 
16 // A small object allocator:
17 // cleanPages:
18 // Pages are freed when they become empty. Requires an extra 4 bytes
19 // per object and can hurt performance. But reduces memory footprint.
20 // pageSize:
21 // Number of objects per page (how many objects are allocated at once).
22 // maxObjectSize:
23 // The size above which we revert to regular new and delete.
24 // threadSafe:
25 // Will ensure that allocs/free's are done in a thread safe manner.
26 // SuperClass:
27 // Allows you to create a UT_SmallObject with an arbitrary base class.
28 // This is useful if you want to have class A, with some subclass B
29 // which is a small object, but another subclass C which is not. In
30 // This case you would have:
31 // class B : public UT_SmallObject<... , A> { };
32 // class C : public A { };
33 // SubClass:
34 // Set this to the class being created. The only reason for this
35 // parameter is so that we won't get linker errors on Windows.
36 #define UT_SMALLOBJECT_CLEANPAGES_DEFAULT true
37 #define UT_SMALLOBJECT_CLEANPAGES_ON true
38 #define UT_SMALLOBJECT_CLEANPAGES_OFF false
39 
40 #define UT_SMALLOBJECT_PAGESIZE_DEFAULT 1024
41 
42 #define UT_SMALLOBJECT_THREADSAFE_DEFAULT true
43 #define UT_SMALLOBJECT_THREADSAFE_ON true
44 #define UT_SMALLOBJECT_THREADSAFE_OFF false
45 
46 #define UT_SMALLOBJECT_MAXOBJECTSIZE_DEFAULT 128
47 
48 // We need a default SuperClass argument. Any empty class with a virtual
49 // destructor will do the trick.
51 {
52 public:
53 };
54 
55 // The UT_SmallObject class template.
56 template <class SubClass,
57  bool cleanPages = UT_SMALLOBJECT_CLEANPAGES_DEFAULT,
58  int pageSize = UT_SMALLOBJECT_PAGESIZE_DEFAULT,
59  bool threadSafe = UT_SMALLOBJECT_THREADSAFE_DEFAULT,
60  size_t maxObjectSize = UT_SMALLOBJECT_MAXOBJECTSIZE_DEFAULT,
61  class SuperClass = UT_SmallObjectDefaultSuperClass>
62 class UT_SmallObject : public SuperClass
63 {
64 public:
65  /// Regular new/delete operators
66  // @{
67  static void *operator new(size_t size)
68  {
70  }
71  static void operator delete(void *p, size_t size)
72  {
74  }
75  // @}
76 
77  // Placement new/delete operators
78  // @{
79  static void *operator new(size_t /*size*/, void *p)
80  {
81  return p;
82  }
83  static void operator delete(void *, void *)
84  {
85  }
86  // @}
87 };
88 
89 #endif
#define UT_SMALLOBJECT_PAGESIZE_DEFAULT
#define UT_SMALLOBJECT_MAXOBJECTSIZE_DEFAULT
#define UT_SMALLOBJECT_THREADSAFE_DEFAULT
static void * allocate(size_t bytes)
static void deallocate(void *p, size_t bytes)
GLsizeiptr size
Definition: glcorearb.h:664
#define UT_SMALLOBJECT_CLEANPAGES_DEFAULT