diff options
author | George Hazan <george.hazan@gmail.com> | 2015-03-21 19:15:39 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-03-21 19:15:39 +0000 |
commit | aebb257da0067c98c292bc62ad73200cc3a9dba7 (patch) | |
tree | bf3d47189a35bfc6c78ac4e6b7baf48a455650b8 /tools/MakeDef/h_object.h | |
parent | 2e286299cea4063e71845616138e92299af42744 (diff) |
DEF-file automatic creator
git-svn-id: http://svn.miranda-ng.org/main/trunk@12473 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'tools/MakeDef/h_object.h')
-rw-r--r-- | tools/MakeDef/h_object.h | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tools/MakeDef/h_object.h b/tools/MakeDef/h_object.h new file mode 100644 index 0000000000..d786c62031 --- /dev/null +++ b/tools/MakeDef/h_object.h @@ -0,0 +1,101 @@ +
+#if !defined( __TOBJECT_H )
+ #define __TOBJECT_H
+
+ #if !defined( __TTYPES_H )
+ #include "h_types.h"
+ #endif
+
+class HSmallAllocator;
+
+struct HRegisteredObject
+{
+ #if !defined( __NO_MEM_MANAGER__ )
+ void* operator new( size_t sz, HSmallAllocator& A );
+ void* operator new( size_t sz );
+ void operator delete( void* ptr );
+ #endif
+};
+
+struct HObject : public HRegisteredObject
+{
+ virtual ~HObject() {}
+};
+
+//====[ Пул для ускорения выделений маленьких кусочков памяти ]================
+
+struct HDataPage
+{
+ HDataPage* next;
+ size_t free;
+};
+
+class HSmallAllocator : public HRegisteredObject
+{
+ friend struct HSmallAllocatorObject;
+ friend struct HSmartSmallAllocatorObject;
+
+protected: size_t pageSize;
+ HDataPage* first;
+
+ void* allocateSpace( size_t );
+public:
+ HSmallAllocator( size_t = 1024 );
+ ~HSmallAllocator();
+
+ char* placeStr( const char* );
+ void* placeData( const void*, size_t );
+
+ friend void* operator new( size_t, HSmallAllocator& );
+
+ virtual void tide();
+};
+
+struct HStaticSmallAllocator : public HSmallAllocator
+{
+ HStaticSmallAllocator( size_t pPageSize );
+
+ virtual void tide();
+};
+
+struct HSmallAllocatorObject
+{
+ void* operator new( size_t, HSmallAllocator& );
+ void* operator new[]( size_t, HSmallAllocator& );
+
+ inline void operator delete( void* )
+ {}
+
+ inline void operator delete[]( void* )
+ {}
+};
+
+struct HSmartSmallAllocatorObject : public HSmallAllocatorObject
+{
+ void* operator new( size_t, HSmallAllocator& );
+ void* operator new[]( size_t, HSmallAllocator& );
+};
+
+inline HSmallAllocator& ALLOCATOR( void* Obj )
+ {
+ void** p = ( void** )Obj;
+
+ return *( HSmallAllocator* )p[ -1 ];
+ }
+
+//====[ Реализация инлайновых методов HRegisteredObject ]======================
+
+ #if !defined( __NO_MEM_MANAGER__ )
+ inline void* HRegisteredObject::operator new( size_t sz, HSmallAllocator& A )
+ { return ::operator new( sz, A );
+ }
+
+ inline void* HRegisteredObject::operator new( size_t sz )
+ { return HNEW( char, sz );
+ }
+
+ inline void HRegisteredObject::operator delete( void* ptr )
+ { ::delete ptr );
+ }
+ #endif
+#endif
|