#include <stl_alloc.h>
Static Public Methods | |
| void * | allocate (size_t n) |
| void | deallocate (void *p, size_t n) |
| void * | reallocate (void *p, size_t old_sz, size_t new_sz) |
Private Types | |
| enum | { __ALIGN = 8 } |
| enum | { __MAX_BYTES = 128 } |
| enum | { __NFREELISTS = __MAX_BYTES/__ALIGN } |
Static Private Methods | |
| size_t | ROUND_UP (size_t bytes) |
| size_t | FREELIST_INDEX (size_t bytes) |
| void * | refill (size_t n) |
| char * | chunk_alloc (size_t size, int &nobjs) |
Private Attributes | |
| __PRIVATE | __pad0__: union obj { union obj * free_list_link |
| char | client_data [1] |
Static Private Attributes | |
| obj *__VOLATILE | free_list [__NFREELISTS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, } |
| char * | start_free = 0 |
| char * | end_free = 0 |
| size_t | heap_size = 0 |
Friends | |
| class | lock |
|
|||||
|
Definition at line 320 of file stl_alloc.h.
00320 {__ALIGN = 8};
|
|
|||||
|
Definition at line 321 of file stl_alloc.h.
00321 {__MAX_BYTES = 128};
|
|
|||||
|
Definition at line 322 of file stl_alloc.h.
00322 {__NFREELISTS = __MAX_BYTES/__ALIGN};
|
|
||||||||||
|
Definition at line 390 of file stl_alloc.h. References __MAX_BYTES, __VOLATILE, __malloc_alloc_template::allocate, free_list, FREELIST_INDEX, lock, refill, and ROUND_UP. Referenced by reallocate.
00391 {
00392 obj * __VOLATILE * my_free_list;
00393 obj * __RESTRICT result;
00394
00395 if (n > (size_t) __MAX_BYTES) {
00396 return(malloc_alloc::allocate(n));
00397 }
00398 my_free_list = free_list + FREELIST_INDEX(n);
00399 // Acquire the lock here with a constructor call.
00400 // This ensures that it is released in exit or during stack
00401 // unwinding.
00402 # ifndef _NOTHREADS
00403 /*REFERENCED*/
00404 lock lock_instance;
00405 # endif
00406 result = *my_free_list;
00407 if (result == 0) {
00408 void *r = refill(ROUND_UP(n));
00409 return r;
00410 }
00411 *my_free_list = result -> free_list_link;
00412 return (result);
00413 };
|
|
||||||||||||||||
|
Definition at line 451 of file stl_alloc.h. References __ALIGN, __MAX_BYTES, __VOLATILE, __malloc_alloc_template::allocate, end_free, free_list, FREELIST_INDEX, heap_size, ROUND_UP, and start_free. Referenced by refill.
00452 {
00453 char * result;
00454 size_t total_bytes = size * nobjs;
00455 size_t bytes_left = end_free - start_free;
00456
00457 if (bytes_left >= total_bytes) {
00458 result = start_free;
00459 start_free += total_bytes;
00460 return(result);
00461 } else if (bytes_left >= size) {
00462 nobjs = bytes_left/size;
00463 total_bytes = size * nobjs;
00464 result = start_free;
00465 start_free += total_bytes;
00466 return(result);
00467 } else {
00468 size_t bytes_to_get = 2 * total_bytes + ROUND_UP(heap_size >> 4);
00469 // Try to make use of the left-over piece.
00470 if (bytes_left > 0) {
00471 obj * __VOLATILE * my_free_list =
00472 free_list + FREELIST_INDEX(bytes_left);
00473
00474 ((obj *)start_free) -> free_list_link = *my_free_list;
00475 *my_free_list = (obj *)start_free;
00476 }
00477 start_free = (char *)malloc(bytes_to_get);
00478 if (0 == start_free) {
00479 int i;
00480 obj * __VOLATILE * my_free_list, *p;
00481 // Try to make do with what we have. That can't
00482 // hurt. We do not try smaller requests, since that tends
00483 // to result in disaster on multi-process machines.
00484 for (i = size; i <= __MAX_BYTES; i += __ALIGN) {
00485 my_free_list = free_list + FREELIST_INDEX(i);
00486 p = *my_free_list;
00487 if (0 != p) {
00488 *my_free_list = p -> free_list_link;
00489 start_free = (char *)p;
00490 end_free = start_free + i;
00491 return(chunk_alloc(size, nobjs));
00492 // Any leftover piece will eventually make it to the
00493 // right free list.
00494 }
00495 }
00496 end_free = 0; // In case of exception.
00497 start_free = (char *)malloc_alloc::allocate(bytes_to_get);
00498 // This should either throw an
00499 // exception or remedy the situation. Thus we assume it
00500 // succeeded.
00501 }
00502 heap_size += bytes_to_get;
00503 end_free = start_free + bytes_to_get;
00504 return(chunk_alloc(size, nobjs));
00505 }
00506 }
|
|
||||||||||||||||
|
Definition at line 416 of file stl_alloc.h. References __MAX_BYTES, __VOLATILE, __malloc_alloc_template::deallocate, free_list, FREELIST_INDEX, and lock. Referenced by reallocate.
00417 {
00418 obj *q = (obj *)p;
00419 obj * __VOLATILE * my_free_list;
00420
00421 if (n > (size_t) __MAX_BYTES) {
00422 malloc_alloc::deallocate(p, n);
00423 return;
00424 }
00425 my_free_list = free_list + FREELIST_INDEX(n);
00426 // acquire lock
00427 # ifndef _NOTHREADS
00428 /*REFERENCED*/
00429 lock lock_instance;
00430 # endif /* _NOTHREADS */
00431 q -> free_list_link = *my_free_list;
00432 *my_free_list = q;
00433 // lock is released here
00434 }
|
|
||||||||||
|
Definition at line 339 of file stl_alloc.h. References __ALIGN. Referenced by allocate, chunk_alloc, deallocate, and refill.
|
|
||||||||||||||||||||
|
Definition at line 543 of file stl_alloc.h. References __MAX_BYTES, allocate, deallocate, and ROUND_UP.
00546 {
00547 void * result;
00548 size_t copy_sz;
00549
00550 if (old_sz > (size_t) __MAX_BYTES && new_sz > (size_t) __MAX_BYTES) {
00551 return(realloc(p, new_sz));
00552 }
00553 if (ROUND_UP(old_sz) == ROUND_UP(new_sz)) return(p);
00554 result = allocate(new_sz);
00555 copy_sz = new_sz > old_sz? old_sz : new_sz;
00556 memcpy(result, p, copy_sz);
00557 deallocate(p, old_sz);
00558 return(result);
00559 }
|
|
||||||||||
|
Definition at line 513 of file stl_alloc.h. References __VOLATILE, chunk_alloc, free_list, and FREELIST_INDEX. Referenced by allocate.
00514 {
00515 int nobjs = 20;
00516 char * chunk = chunk_alloc(n, nobjs);
00517 obj * __VOLATILE * my_free_list;
00518 obj * result;
00519 obj * current_obj, * next_obj;
00520 int i;
00521
00522 if (1 == nobjs) return(chunk);
00523 my_free_list = free_list + FREELIST_INDEX(n);
00524
00525 /* Build free list in chunk */
00526 result = (obj *)chunk;
00527 *my_free_list = next_obj = (obj *)(chunk + n);
00528 for (i = 1; ; i++) {
00529 current_obj = next_obj;
00530 next_obj = (obj *)((char *)next_obj + n);
00531 if (nobjs - 1 == i) {
00532 current_obj -> free_list_link = 0;
00533 break;
00534 } else {
00535 current_obj -> free_list_link = next_obj;
00536 }
00537 }
00538 return(result);
00539 }
|
|
||||||||||
|
Definition at line 324 of file stl_alloc.h. References __ALIGN. Referenced by allocate, chunk_alloc, and reallocate.
|
|
|||||
|
Definition at line 385 of file stl_alloc.h. Referenced by allocate, and deallocate. |
|
|||||
|
Definition at line 329 of file stl_alloc.h. |
|
|||||
|
Definition at line 330 of file stl_alloc.h. |
|
|||||
|
Definition at line 659 of file stl_alloc.h. Referenced by chunk_alloc. |
|
|||||
|
Definition at line 672 of file stl_alloc.h. Referenced by allocate, chunk_alloc, deallocate, and refill. |
|
|||||
|
Definition at line 662 of file stl_alloc.h. Referenced by chunk_alloc. |
|
|||||
|
Definition at line 656 of file stl_alloc.h. Referenced by chunk_alloc. |
| Documentation generated on Thu May 2 15:03:14 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |