Changeset e36e3a in git
- Timestamp:
- Nov 23, 1999, 9:40:13 PM (24 years ago)
- Branches:
- (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
- Children:
- d47e6fd256e2e97a44cc9bae4b289a40732b3e98
- Parents:
- 3b8058716b41cc9477cc0c90c845072db5c5e702
- Location:
- omalloc
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
omalloc/Makefile.in
r3b8058 re36e3a 4 4 ### Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 ### Created: 11/99 6 ### Version: $Id: Makefile.in,v 1. 1.1.1 1999-11-18 17:45:53obachman Exp $6 ### Version: $Id: Makefile.in,v 1.2 1999-11-23 20:40:11 obachman Exp $ 7 7 ################################################################# 8 8 … … 47 47 # normal C source files 48 48 CSOURCES=omAlloc.c omList.c omDebug.c omPage.c omLocal.c omFindExec.c \ 49 omTrack.c gmalloc.c49 omTrack.c omCheck.c gmalloc.c 50 50 51 51 SOURCES=${CSOURCES} -
omalloc/omAlloc.c
r3b8058 re36e3a 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omAlloc.c,v 1. 2 1999-11-22 18:12:57obachman Exp $6 * Version: $Id: omAlloc.c,v 1.3 1999-11-23 20:40:12 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_ALLOC_C … … 16 16 #include "omList.h" 17 17 18 19 /******************************************************************* 20 * 21 * global variables 22 * 23 *******************************************************************/ 18 24 19 25 omBinPage_t om_ZeroPage[] = {{0, NULL, NULL, NULL, NULL}}; … … 24 30 omSpecBin om_SpecBin = NULL; 25 31 26 27 #include <stdlib.h> 32 /******************************************************************* 33 * 34 * Alloc routines which we do not define as macros 35 * 36 *******************************************************************/ 37 void* _omReallocBlock(void* old_addr, size_t old_size, size_t new_size) 38 { 39 void* new_addr; 40 if (old_addr == NULL) __omTypeAllocBlock(void*, new_addr, new_size); 41 else 42 { 43 if (new_size <= OM_MAX_BLOCK_SIZE && old_size <= OM_MAX_BLOCK_SIZE) 44 { 45 omBin __om_new_bin = omSmallSize2Bin(new_size); 46 omBin __om_old_bin = omSmallSize2Bin(old_size); 47 if (__om_new_bin != __om_old_bin) 48 { 49 __omTypeAllocBlock(void*, new_addr, new_size); 50 omMemcpyW(new_addr, old_addr, 51 (__om_old_bin->sizeW > __om_new_bin->sizeW ? 52 __om_new_bin->sizeW : __om_old_bin->sizeW)); 53 __omFreeBin(old_addr); 54 } 55 } 56 else if (new_size > OM_MAX_BLOCK_SIZE && old_size > OM_MAX_BLOCK_SIZE) 57 { 58 new_addr = (type) omLargeBlockRealloc(new_size, old_addr, old_size); 59 } 60 else 61 { 62 __omTypeAllocBlock(void*, new_addr, new_size); 63 memcpy(new_addr, old_addr, (old_size > new_size ? new_size : old_size)); 64 } 65 } 66 return new_addr; 67 } 68 69 void* _omRealloc0Block(void* old_addr, size_t old_size, size_t new_size) 70 { 71 void* new_addr; 72 int __om_fill = new_size - old_size; 73 new_addr = _omReallocBlock(void*, new_addr, new_size, old_addr, old_size); 74 if (_om_fill > 0) memset(((void*) new_addr) + __om_fill, 0, __om_fill); 75 return new_addr; 76 } 77 78 #ifdef OM_ALIGNMENT_NEEDS_WORK 79 void* _omReallocAlignedBlock(void* old_addr, size_t old_size, size_t new_size) 80 { 81 void* new_addr; 82 if (old_addr == NULL) __omTypeAllocAlignedBlock(void*, new_addr, new_size); 83 else 84 { 85 if (new_size <= OM_MAX_BLOCK_SIZE && old_size <= OM_MAX_BLOCK_SIZE) 86 { 87 omBin __om_new_bin = omSmallSize2AlignedBin(new_size); 88 omBin __om_old_bin = omSmallSize2AlignedBin(old_size); 89 if (__om_new_bin != __om_old_bin) 90 { 91 __omTypeAllocAlignedBlock(void*, new_addr, new_size); 92 omMemcpyW(new_addr, old_addr, 93 (__om_old_bin->sizeW > __om_new_bin->sizeW ? 94 __om_new_bin->sizeW : __om_old_bin->sizeW)); 95 __omFreeBin(old_addr); 96 } 97 } 98 else if (new_size > OM_MAX_BLOCK_SIZE && old_size > OM_MAX_BLOCK_SIZE) 99 { 100 new_addr = (type) omLargeBlockRealloc(new_size, old_addr, old_size); 101 } 102 else 103 { 104 __omTypeAllocAllignedBlock(void*, new_addr, new_size); 105 memcpy(new_addr, old_addr, (old_size > new_size ? new_size : old_size)); 106 } 107 } 108 } 109 110 void* _omRealloc0AlignedBlock(void* old_addr, size_t old_size, size_t new_size) 111 { 112 void* new_addr; 113 int __om_fill = new_size - old_size; 114 __omTypeReallocAlignedBlock(void*, new_addr, new_size, old_addr, old_size); 115 if (_om_fill > 0) memset(((void*) new_addr) + __om_fill, 0, __om_fill); 116 return new_addr; 117 } 118 #endif /* OM_ALIGNMENT_NEEDS_WORK */ 119 120 void* _omReallocChunk(void* old_addr, size_t new_size) 121 { 122 void* new_addr; 123 if (old_addr == NULL) __omTypeAllocChunk(void*, new_addr, new_size); 124 else 125 { 126 void* __old_addr = ((void*) (old_addr)) - SIZEOF_OM_ALIGNMENT; 127 omBinPage __om_page = *((omBinPage*) __old_addr); 128 size_t __new_size = new_size + SIZEOF_OM_ALIGNMENT; 129 void* __new_addr; 130 if (__new_size <= MAX_BLOCK_SIZE && __om_page != om_LargePage) 131 { 132 omBin __om_old_bin = omGetTopBinOfPage(__om_page); 133 omBin __om_new_bin = omSmallSize2Bin(__new_size); 134 if (__om_old_bin != __om_new_bin) 135 { 136 __omTypeAllocBin(void*, __new_addr, __new_size); 137 omMemcpyW(__new_addr, __old_addr, 138 (__om_old_bin->sizeW > __om_new_bin->sizeW ? 139 __om_new_bin->sizeW : __om_old_bin->sizeW)); 140 *((void**) __new_addr) = (void*) __om_new_bin->current_page; 141 __omFreeBin(__old_addr); 142 new_addr = (type) (__new_addr + SIZEOF_OM_ALIGNMENT); 143 } 144 else 145 { 146 new_addr = (type) old_addr; 147 } 148 } 149 else if (__new_size > MAX_BLOCK_SIZE && __om_page == om_LargePage) 150 { 151 __new_addr = omReallocLargeChunk(__old_addr, __new_size); 152 *((void**) __new_addr) = (void*) om_LargePage; 153 new_addr = (type) (__new_addr + SIZEOF_OM_ALIGNMENT); 154 } 155 else 156 { 157 __omTypeAllocChunk(void*, new_addr, new_size); 158 if (__om_page != om_LargePage) 159 { 160 omBin old_bin = omGetTopBinOfPage(__om_page); 161 omMemcpyW(new_addr, old_addr, old_bin->sizeW - 1); 162 } 163 else 164 { 165 memcpy(new_addr, old_addr, new_size); 166 } 167 } 168 } 169 return new_addr; 170 } 171 172 #ifdef OM_ALIGNMENT_NEEDS_WORK 173 void* _omReallocAlignedChunk(void* old_addr, size_t new_size) 174 { 175 void* new_addr; 176 if (old_addr == NULL) __omTypeAllocAlignedChunk(void*, new_addr, new_size); 177 else 178 { 179 void* __old_addr = ((void*) (old_addr)) - SIZEOF_OM_CHUNK_ALIGNMENT; 180 omBinPage __om_page = *((omBinPage*) __old_addr); 181 size_t __new_size = new_size + SIZEOF_OM_CHUNK_ALIGNMENT; 182 void* __new_addr; 183 if (__new_size <= MAX_BLOCK_SIZE && __om_page != om_LargePage) 184 { 185 omBin __om_old_bin = omGetTopBinOfPage(__om_page); 186 omBin __om_new_bin = omSmallSize2AlignedBin(__new_size); 187 if (__om_old_bin != __om_new_bin) 188 { 189 __omTypeAllocBin(void*, __new_addr, __new_size); 190 omMemcpyW(__new_addr, __old_addr, 191 (__om_old_bin->sizeW > __om_new_bin->sizeW ? 192 __om_new_bin->sizeW : __om_old_bin->sizeW)); 193 *((void**) __new_addr) = (void*) __om_new_bin->current_page; 194 __omFreeBin(__old_addr); 195 new_addr = (type) (__new_addr + SIZEOF_OM_ALIGNMENT); 196 } 197 else 198 { 199 new_addr = (type) old_addr; 200 } 201 } 202 else if (__new_size > MAX_BLOCK_SIZE && __om_page == om_LargePage) 203 { 204 __new_addr = omReallocLargeChunk(__old_addr, __new_size); 205 *((void**) __new_addr) = (void*) om_LargePage; 206 new_addr = (type) (__new_addr + SIZEOF_OM_CHUNK_ALIGNMENT); 207 } 208 else 209 { 210 __omTypeAllocChunk(void*, new_addr, new_size); 211 if (__om_page != om_LargePage) 212 { 213 omBin old_bin = omGetTopBinOfPage(__om_page); 214 memcpy(new_addr, old_addr, 215 old_bin->sizeW*SIZEOF_LONG - SIZEOF_OM_CHUNK_ALIGNMENT); 216 } 217 else 218 { 219 memcpy(new_addr, old_addr, new_size); 220 } 221 __omFreeAlignedChunk(old_addr); 222 } 223 } 224 return new_addr; 225 } 226 #endif /* OM_ALIGNMENT_NEEDS_WORK */ 227 228 229 /******************************************************************* 230 * 231 * Local stuff 232 * 233 *******************************************************************/ 234 /* this should go away */ 28 235 #define AllocSizeOf(x) _omAllocBlock(sizeof(x)) 29 236 #define FreeSizeOf(addr, x) _omFreeBin(addr) … … 572 779 } 573 780 574 #include "omDebug.h"575 576 781 void omDeleteStickyBinTag(omBin bin, unsigned long sticky) 577 782 { … … 579 784 omBin sticky_bin = NULL; 580 785 581 omdCheckBin(bin, 10);582 786 if (sticky == 0) 583 787 { … … 602 806 FreeSizeOf(sticky_bin, omBin_t); 603 807 } 604 omdCheckBin(bin, 10);605 808 } 606 809 -
omalloc/omPrivate.h
r3b8058 re36e3a 5 5 * Author: obachman (Olaf Bachmann) 6 6 * Created: 11/99 7 * Version: $Id: omPrivate.h,v 1. 2 1999-11-22 18:12:59obachman Exp $7 * Version: $Id: omPrivate.h,v 1.3 1999-11-23 20:40:13 obachman Exp $ 8 8 *******************************************************************/ 9 9 #ifndef OM_PRIVATE_H … … 57 57 long used_blocks; /* number of used blocks of this page */ 58 58 void* current; /* pointer to current freelist */ 59 omBinPage next; /* next/prev pointer of pages */60 omBinPage prev;61 void* bin_sticky; /* bin this page belongs to with62 sticky tag of page hidden in ptr*/59 omBinPage next; /* next/prev pointer of pages */ 60 omBinPage prev; 61 void* bin_sticky; /* bin this page belongs to with 62 sticky tag of page hidden in ptr*/ 63 63 }; 64 64 65 /* Change this appropriately, if you change omBinPage */ 65 66 /* However, make sure that omBinPage is a multiple of SIZEOF_MAX_TYPE */ … … 73 74 struct omBin_s 74 75 { 75 omBinPage current_page; /* page of current freelist */76 omBinPage last_page; /* pointer to last page of freelist */77 omBin next; /* sticky bins of the same size */76 omBinPage current_page; /* page of current freelist */ 77 omBinPage last_page; /* pointer to last page of freelist */ 78 omBin next; /* sticky bins of the same size */ 78 79 long sizeW; /* size in words */ 79 80 long max_blocks; /* if > 0 # blocks in one page, … … 85 86 { 86 87 omSpecBin next; /* pointer to next bin */ 87 omBin bin; /* pointer to bin itself */88 omBin bin; /* pointer to bin itself */ 88 89 long max_blocks; /* max_blocks of bin*/ 89 90 long ref; /* ref count */ … … 176 177 /*******************************************************************/ 177 178 /* Block */ 178 #define omSmallSize2Bin(size) om_Size2Bin[((size) -1) >> LOG_SIZEOF_OM_ALIGNMENT] 179 #define omSize2Bin(size) ((size) <= OM_MAX_BLOCK_SIZE ? omSmallSize2Bin(size) : om_LargeBin) 179 #define omSmallSize2Bin(size) om_Size2Bin[((size) -1)>>LOG_SIZEOF_OM_ALIGNMENT] 180 #define omSize2Bin(size) ((size) <= OM_MAX_BLOCK_SIZE ? \ 181 omSmallSize2Bin(size) : om_LargeBin) 180 182 181 183 #define omAllocLargeBlock(size) OM_MALLOC(size) … … 213 215 while (0) 214 216 217 #ifdef OM_ALIGNMENT_NEEDS_WORK 218 #define __omTypeAllocAlignedBlock(type, addr, size) \ 219 do \ 220 { \ 221 if (size <= OM_MAX_BLOCK_SIZE) \ 222 { \ 223 omBin __om_bin = omSmallSize2AlignedBin(size); \ 224 __omTypeAllocBin(type, addr, __om_bin); \ 225 } \ 226 else \ 227 { \ 228 addr = (type) omAllocLargeBlock(size); \ 229 } \ 230 } \ 231 while(0) 232 233 #define __omTypeAlloc0AlignedBlock(type, addr, size) \ 234 do \ 235 { \ 236 if (size <= OM_MAX_BLOCK_SIZE) \ 237 { \ 238 omBin __om_bin = omSmallSize2AlignedBin(size); \ 239 __omTypeAlloc0Bin(type, addr, __om_bin); \ 240 } \ 241 else \ 242 { \ 243 addr = (type) omAllocLargeBlock(size); \ 244 memset(addr, 0, size); \ 245 } \ 246 } \ 247 while (0) 248 249 #else /* ! OM_ALIGNMENT_NEEDS_WORK */ 250 #define __omTypeAllocAlignedBlock __omTypeAllocBlock 251 #define __omTypeAlloc0AlignedBlock __omTypeAlloc0Block 252 #endif /* OM_ALIGNMENT_NEEDS_WORK */ 253 215 254 #define __omFreeBlock(addr, size) \ 216 255 do \ … … 239 278 if (__om_size <= OM_MAX_BLOCK_SIZE) \ 240 279 { \ 241 omBin __om_bin = omSmallSize2Bin(__om_size); 280 omBin __om_bin = omSmallSize2Bin(__om_size); \ 242 281 __omTypeAllocBin(void*, __om_addr, __om_bin); \ 243 282 *((void**) __om_addr) = (void*) __om_bin->current_page; \ … … 246 285 { \ 247 286 __om_addr = omAllocLargeChunk(__om_size); \ 248 *((void**) __om_addr) = om_LargePage;\287 *((void**) __om_addr) = (void*) om_LargePage; \ 249 288 } \ 250 289 addr = (type) (__om_addr + SIZEOF_OM_ALIGNMENT); \ … … 267 306 __om_addr = omAllocLargeChunk(__om_size); \ 268 307 memset(__om_addr, 0, __om_size); \ 269 *((void**) __om_addr) = om_LargePage;\308 *((void**) __om_addr) = (void*) om_LargePage; \ 270 309 } \ 271 310 addr = (type) (__om_addr + SIZEOF_OM_ALIGNMENT); \ 272 311 } \ 273 312 while (0) 313 314 #ifdef OM_ALIGNMENT_NEEDS_WORK 315 316 #define __omTypeAllocAlignedChunk(type, addr, size) \ 317 do \ 318 { \ 319 void* __om_addr; \ 320 size_t __om_size = (size) + SIZEOF_OM_CHUNK_ALIGNMENT; \ 321 if (__om_size <= OM_MAX_BLOCK_SIZE) \ 322 { \ 323 omBin __om_bin = omSmallSize2AlignedBin(__om_size); \ 324 __omTypeAllocBin(void*, __om_addr, __om_bin); \ 325 *((void**) __om_addr) = (void*) __om_bin->current_page; \ 326 } \ 327 else \ 328 { \ 329 __om_addr = omAllocLargeChunk(__om_size); \ 330 *((void**) __om_addr) = (void*) om_LargePage; \ 331 } \ 332 addr = (type) (__om_addr + SIZEOF_OM_CHUNK_ALIGNMENT); \ 333 } \ 334 while (0) 335 336 #define __omTypeAlloc0AlignedChunk(type, addr, size) \ 337 do \ 338 { \ 339 void* __om_addr; \ 340 size_t __om_size = (size) + SIZEOF_OM_CHUNK_ALIGNMENT; \ 341 if (__om_size <= OM_MAX_BLOCK_SIZE) \ 342 { \ 343 omBin __om_bin = omSmallSize2Bin(__om_size); \ 344 __omTypeAlloc0Bin(void*, __om_addr, __om_bin); \ 345 *((void**) __om_addr) = (void*) __om_bin->current_page; \ 346 } \ 347 else \ 348 { \ 349 __om_addr = omAllocLargeChunk(__om_size); \ 350 memset(__om_addr, 0, __om_size); \ 351 *((void**) __om_addr) = (void*) om_LargePage; \ 352 } \ 353 addr = (type) (__om_addr + SIZEOF_OM_CHUNK_ALIGNMENT); \ 354 } \ 355 while (0) 356 357 #define __omFreeAlignedChunk(addr) \ 358 do \ 359 { \ 360 void* __addr = ((void*) (addr)) - SIZEOF_OM_CHUNK_ALIGNMENT; \ 361 omBinPage __om_page = *((omBinPage*) __addr); \ 362 __omFreeToPage(__addr, __om_page); \ 363 } \ 364 while (0) 365 366 367 #else /* ! OM_ALIGNMENT_NEEDS_WORK */ 368 #define __omTypeAllocAlignedChunk __omTypeAllocChunk 369 #define __omTypeAlloc0AlignedChunk __omTypeAlloc0Chunk 370 #define __omFreeAlignedChunk __omFreeChunk 371 #endif /* OM_ALIGNMENT_NEEDS_WORK */ 274 372 275 373 #define __omFreeChunk(addr) \ … … 290 388 #if defined(OM_INLINE) 291 389 292 #define OM_ALLOCBIN_FUNC_WRAPPER(func) \293 OM_INLINE void* _om##func (omBin bin) \390 #define OM_ALLOCBIN_FUNC_WRAPPER(func) \ 391 OM_INLINE void* _om##func (omBin bin) \ 294 392 { \ 295 393 void* addr; \ 296 __omType##func (void*, addr, bin); \394 __omType##func (void*, addr, bin); \ 297 395 return addr; \ 298 396 }
Note: See TracChangeset
for help on using the changeset viewer.