Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

pi_mem.c

Go to the documentation of this file.
00001 /* 00002 File: PI_Memory.c 00003 00004 Contains: 00005 00006 Written by: U. J. Krabbenhoeft 00007 00008 Version: 00009 00010 Copyright: � 1993-1997 by Heidelberger Druckmaschinen AG, all rights reserved. 00011 00012 */ 00013 #ifndef PI_BasicTypes_h 00014 #include "PI_Basic.h" 00015 #endif 00016 00017 #ifndef PI_Memory_h 00018 #include "PI_Mem.h" 00019 #endif 00020 00021 #ifndef PI_Machine_h 00022 #include "PI_Mach.h" 00023 #endif 00024 00025 #include <string.h> 00026 #ifdef IntelMode 00027 #include "PI_Swap.h" 00028 #endif 00029 00030 #if __IS_MAC 00031 void Debugger(); 00032 #endif 00033 00034 /* -------------------------------------------------------------------------- 00035 00036 Ptr SmartNewPtr(Size byteCount, 00037 OSErr* resultCode) 00038 00039 Abstract: 00040 00041 Params: 00042 00043 Return: 00044 noErr successful 00045 00046 -------------------------------------------------------------------------- */ 00047 Ptr SmartNewPtr(Size byteCount, 00048 OSErr* resultCode) 00049 { 00050 Ptr aPtr; 00051 aPtr = (Ptr)LH_malloc(byteCount); 00052 if (aPtr == 0) 00053 *resultCode = notEnoughMemoryErr; 00054 else 00055 *resultCode = 0; 00056 return aPtr; 00057 } 00058 00059 00060 /* -------------------------------------------------------------------------- 00061 00062 Ptr SmartNewPtrClear(Size byteCount, 00063 OSErr* resultCode) 00064 00065 Abstract: 00066 00067 Params: 00068 00069 Return: 00070 00071 -------------------------------------------------------------------------- */ 00072 Ptr SmartNewPtrClear(Size byteCount, 00073 OSErr* resultCode) 00074 { 00075 Ptr ptr = NULL; 00076 00077 ptr = SmartNewPtr(byteCount, resultCode); 00078 00079 if (ptr != NULL) 00080 { 00081 memset( ptr, 0, byteCount ); 00082 } 00083 return ptr; 00084 00085 } 00086 00087 00088 /* -------------------------------------------------------------------------- 00089 00090 Ptr DisposeIfPtr(Ptr thePtr) 00091 00092 Abstract: 00093 00094 Params: 00095 00096 Return: 00097 00098 -------------------------------------------------------------------------- */ 00099 Ptr DisposeIfPtr(Ptr thePtr) 00100 { 00101 if (thePtr) 00102 { 00103 LH_free(thePtr); 00104 } 00105 return NULL; 00106 } 00107 00108 #ifdef __MWERKS__ 00109 extern pascal Ptr NewPtr(Size byteCount); 00110 extern pascal void DisposePtr(Ptr p); 00111 #endif 00112 00113 #ifdef LH_MEMORY_DEBUG 00114 typedef struct 00115 { 00116 void* p; 00117 long l; 00118 } LH_PointerType; 00119 static LH_PointerType PListe[2001]; 00120 static long PListeCount = 0; 00121 00122 /* -------------------------------------------------------------------------- 00123 00124 void LH_mallocInit() 00125 00126 Abstract: 00127 00128 Params: 00129 00130 Return: 00131 00132 -------------------------------------------------------------------------- */ 00133 void LH_mallocInit() 00134 { 00135 long i; 00136 for (i = 0; i < 2000; i++) 00137 { 00138 PListe[i].p = 0; 00139 PListe[i].l = 0; 00140 } 00141 PListeCount = 0; 00142 } 00143 00144 00145 /* -------------------------------------------------------------------------- 00146 00147 void* LH_malloc(long a) 00148 00149 Abstract: 00150 00151 Params: 00152 00153 Return: 00154 00155 -------------------------------------------------------------------------- */ 00156 void* LH_malloc(long a) 00157 { 00158 long i; 00159 #ifdef __MWERKS__ 00160 void* aPtr = NewPtr(a); 00161 #else 00162 void* aPtr = malloc(a); 00163 #endif 00164 00165 for (i = 0; i < PListeCount; i++) 00166 { 00167 if (aPtr < PListe[i].p) 00168 continue; 00169 if (aPtr >= (char*)PListe[i].p + PListe[i].l) 00170 continue; 00171 Debugger(); 00172 } 00173 00174 for (i = 0; i < PListeCount; i++) 00175 { 00176 if (PListe[i].p == 0) 00177 break; 00178 } 00179 PListe[i].p = aPtr; 00180 PListe[i].l = a; 00181 if (i >= PListeCount) 00182 { 00183 if (PListeCount < 2000) 00184 PListeCount++; 00185 } 00186 return aPtr; 00187 } 00188 00189 00190 /* -------------------------------------------------------------------------- 00191 00192 void LH_free(void* a) 00193 00194 Abstract: 00195 00196 Params: 00197 00198 Return: 00199 00200 -------------------------------------------------------------------------- */ 00201 void LH_free(void* a) 00202 { 00203 long i; 00204 for (i = 0; i < PListeCount; i++) 00205 { 00206 if (PListe[i].p == a) 00207 break; 00208 } 00209 if (i < PListeCount) 00210 { 00211 PListe[i].p = 0; 00212 PListe[i].l = 0; 00213 #ifdef __MWERKS__ 00214 DisposePtr(a); 00215 #else 00216 free(a); 00217 #endif 00218 00219 } 00220 else 00221 { 00222 Debugger(); 00223 } 00224 } 00225 #else 00226 00227 /* -------------------------------------------------------------------------- 00228 00229 void LH_mallocInit() 00230 00231 Abstract: 00232 00233 Params: 00234 00235 Return: 00236 00237 -------------------------------------------------------------------------- */ 00238 void LH_mallocInit() 00239 { 00240 } 00241 00242 00243 /* -------------------------------------------------------------------------- 00244 00245 void* LH_malloc(long a) 00246 00247 Abstract: 00248 00249 Params: 00250 00251 Return: 00252 00253 -------------------------------------------------------------------------- */ 00254 void* LH_malloc(long a) 00255 { 00256 #ifdef __MWERKS__ 00257 return NewPtr(a); 00258 #else 00259 return malloc(a); 00260 #endif 00261 00262 } 00263 00264 00265 /* -------------------------------------------------------------------------- 00266 00267 void LH_free(void* a) 00268 00269 Abstract: 00270 00271 Params: 00272 00273 Return: 00274 00275 -------------------------------------------------------------------------- */ 00276 void LH_free(void* a) 00277 { 00278 #ifdef __MWERKS__ 00279 DisposePtr((Ptr)a); 00280 #else 00281 free(a); 00282 #endif 00283 00284 } 00285 #endif 00286 00287 00288 /* -------------------------------------------------------------------------- 00289 00290 void SetMem(void* bytePtr, 00291 size_t numBytes, 00292 unsigned char byteValue); 00293 00294 Abstract: 00295 00296 Params: 00297 00298 Return: 00299 00300 -------------------------------------------------------------------------- */ 00301 void SetMem(void* bytePtr, 00302 size_t numBytes, 00303 unsigned char byteValue); 00304 void SetMem(void* bytePtr, 00305 size_t numBytes, 00306 unsigned char byteValue) 00307 { 00308 memset(bytePtr, byteValue, numBytes); 00309 } 00310 00311 /*void SecondsToDate(unsigned long secs, DateTimeRec *d) 00312 { 00313 secs=secs; 00314 d->year = 55; 00315 d->month = 8; 00316 d->day = 8; 00317 d->hour = 0; 00318 d->minute = 0; 00319 d->second = 0; 00320 d->dayOfWeek = 0; 00321 }*/ 00322 00323 #if !__IS_MAC 00324 /* -------------------------------------------------------------------------- 00325 00326 void BlockMove(const void* srcPtr, 00327 void* destPtr, 00328 Size byteCount); 00329 00330 Abstract: 00331 00332 Params: 00333 00334 Return: 00335 00336 -------------------------------------------------------------------------- */ 00337 void BlockMove(const void* srcPtr, 00338 void* destPtr, 00339 Size byteCount) 00340 { 00341 memmove(destPtr, srcPtr, byteCount); 00342 } 00343 #endif 00344 00345 #ifdef IntelMode 00346 /* -------------------------------------------------------------------------- 00347 00348 void SwapLongOffset(void* p, 00349 unsigned long a, 00350 unsigned long b) 00351 00352 Abstract: 00353 00354 Params: 00355 00356 Return: 00357 00358 -------------------------------------------------------------------------- */ 00359 void SwapLongOffset(void* p, 00360 unsigned long a, 00361 unsigned long b) 00362 { 00363 unsigned long* aPtr = (unsigned long*)((char*)p + a); 00364 unsigned long* bPtr = (unsigned long*)((char*)p + b); 00365 while (aPtr < bPtr) 00366 { 00367 SwapLong(aPtr); 00368 aPtr++; 00369 } 00370 } 00371 00372 00373 /* -------------------------------------------------------------------------- 00374 00375 void SwapShortOffset(void* p, 00376 unsigned long a, 00377 unsigned long b); 00378 00379 Abstract: 00380 00381 Params: 00382 00383 Return: 00384 00385 -------------------------------------------------------------------------- */ 00386 void SwapShortOffset(void* p, 00387 unsigned long a, 00388 unsigned long b); 00389 void SwapShortOffset(void* p, 00390 unsigned long a, 00391 unsigned long b) 00392 { 00393 unsigned short* aPtr = (unsigned short*)((char*)p + a); 00394 unsigned short* bPtr = (unsigned short*)((char*)p + b); 00395 while (aPtr < bPtr) 00396 { 00397 SwapShort(aPtr); 00398 aPtr++; 00399 } 00400 } 00401 00402 #endif 00403 00404

Generated on Sat May 15 19:41:14 2004 for test by doxygen 1.3.7