|
QSDK 1.1 Documentation |
00001 /*- 00002 * Copyright (c) 2001-2003 Qube Software, Ltd. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are 00007 * met: 00008 * 00009 * 1. Redistributions of the source code must retain the above copyright 00010 * notice, this list of conditions and the following disclaimer. 00011 * 00012 * 2. Any redistribution solely in binary form must conspicuously 00013 * reproduce the following disclaimer in documentation provided with the 00014 * binary redistribution. 00015 * 00016 * THIS SOFTWARE IS PROVIDED ``AS IS'', WITHOUT ANY WARRANTIES, EXPRESS 00017 * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. LICENSOR SHALL 00019 * NOT BE LIABLE FOR ANY LOSS OR DAMAGES RESULTING FROM THE USE OF THIS 00020 * SOFTWARE, EITHER ALONE OR IN COMBINATION WITH ANY OTHER SOFTWARE. 00021 * 00022 * $Qube: Q/utils/sdk/allocator.h,v 1.21 2003/06/19 12:50:38 peterj Exp $ 00023 */ 00024 00025 00026 #ifndef __allocator_h__ 00027 #define __allocator_h__ 00028 00029 #include <Q/linkage.h> 00030 00031 #ifndef UTILS_BEGIN 00032 #define UTILS_BEGIN namespace Utils { 00033 #define UTILS_END } 00034 #endif 00035 00036 #include <Q/utils.h> 00037 00038 UTILS_BEGIN 00039 00085 struct EXPORT_QUTILS Allocator 00086 { 00091 virtual void* alloc(size_t size) = 0; 00096 virtual void free(void* p) = 0; 00100 virtual size_t size(void* p) const = 0; 00104 virtual size_t allocatedMemory() const = 0; 00110 virtual void* alloc(size_t amt, unsigned int color) 00111 { return alloc(amt); } 00115 virtual size_t internalFree() const = 0; 00116 virtual unsigned int color(void*) const { return 0; } 00117 virtual Utils::Result setColor(void*, unsigned int) 00118 { return Utils::NotImplemented; } 00119 virtual bool valid(void*) const { return false; } 00120 virtual Utils::Result setDefaultColor(unsigned int col, 00121 unsigned int* oldCol) 00122 { return Utils::NotImplemented; } 00123 virtual unsigned int defaultColor() const { return 0; } 00124 virtual size_t allocatedColorMemory(unsigned int col) const 00125 { return 0; } 00126 virtual size_t freeColorMemory(unsigned int col) const 00127 { return 0; } 00128 virtual void adjustColorMemory(unsigned int col, int amt) 00129 {}; 00130 00134 static Allocator* theAllocator(); 00135 }; 00136 00140 struct EXPORT_QUTILS HostAllocator: public Allocator 00141 { 00142 virtual void* alloc(size_t); 00143 virtual void free(void*) {} 00144 virtual size_t size(void*) const; 00145 virtual size_t allocatedMemory() const { return 0; } 00146 virtual void* alloc(size_t x, char type) { return alloc(x); } 00147 virtual size_t internalFree() const { return 0; } 00148 00149 private: 00150 00151 size_t lastBlockSize_; 00152 }; 00153 00154 00162 struct EXPORT_QUTILS MemoryColor 00163 { 00167 MemoryColor(unsigned int col); 00168 00169 ~MemoryColor() { reset(); } 00170 00174 unsigned int lastColor() const { return lastColor_; } 00175 00176 00180 void reset(); 00181 00182 private: 00183 00184 unsigned int lastColor_; 00185 }; 00186 00187 00188 UTILS_END 00189 00190 #endif /* __allocator_h__ */ 00191 00192 00193
|
|
|
Qube Software Limited © 2000-2004
|
|