Changeset 212fc04 in git for omalloc/omAlloc.c
- Timestamp:
- Nov 22, 1999, 7:13:00 PM (24 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 6ea5825fc0e0bfabf56883aee9dac9b5bbe415fe
- Parents:
- e6908a0f43ea328a1aa0c3942e8d309db7de26d5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
omalloc/omAlloc.c
re6908a0 r212fc04 4 4 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann) 5 5 * Created: 11/99 6 * Version: $Id: omAlloc.c,v 1. 1.1.1 1999-11-18 17:45:53obachman Exp $6 * Version: $Id: omAlloc.c,v 1.2 1999-11-22 18:12:57 obachman Exp $ 7 7 *******************************************************************/ 8 8 #ifndef OM_ALLOC_C … … 25 25 26 26 27 #if 028 #include "mmemory.h"29 #else30 27 #include <stdlib.h> 31 #define AllocSizeOf(x) malloc(sizeof(x)) 32 #define FreeSizeOf(addr, x) free(addr) 33 #endif 28 #define AllocSizeOf(x) _omAllocBlock(sizeof(x)) 29 #define FreeSizeOf(addr, x) _omFreeBin(addr) 34 30 35 31 /* Get new page and initialize */ … … 129 125 130 126 /* bin->current_page is empty, get new bin->current_page, return addr*/ 131 void* omAllocBinFromFullPage(omBin Page page, omBinbin)127 void* omAllocBinFromFullPage(omBin bin) 132 128 { 133 129 void* addr; … … 135 131 omAssume(bin->current_page->current == NULL); 136 132 133 if (bin->current_page != om_ZeroPage) 134 { 135 omAssume(bin->last_page != NULL); 136 bin->current_page->used_blocks = 0; 137 } 138 137 139 if (bin->current_page->next != NULL) 138 140 { … … 154 156 } 155 157 156 void* omAllocBlockFromFullPage(omBinPage page, omBin bin,157 const size_t size, const int zero)158 {159 void* addr;160 161 if (bin == om_LargeBin)162 {163 addr = omMallocFromSystem(size + SIZEOF_OM_ALIGNMENT);164 if (zero) memset(addr, 0, size);165 return addr;166 }167 else168 {169 addr = omAllocBinFromFullPage(page, bin);170 if (zero) omMemsetW(addr, 0, bin->sizeW);171 return addr;172 }173 }174 158 175 159 /* page->used_blocks == 0, so, either free page or reallocate to … … 194 178 else 195 179 { 196 bin = om BinOfPage(page);180 bin = omGetBinOfPage(page); 197 181 if (page->current != NULL || bin->max_blocks <= 1) 198 182 { … … 277 261 s_bin->bin->current_page = om_ZeroPage; 278 262 s_bin->bin->last_page = NULL; 263 s_bin->bin->next = NULL; 279 264 s_bin->bin->sizeW = sizeW; 280 265 s_bin->bin->max_blocks = max_blocks; … … 396 381 } 397 382 398 staticvoid omPrintBinStat(FILE * fd, omBin bin)383 void omPrintBinStat(FILE * fd, omBin bin) 399 384 { 400 385 int pages = 0, used_blocks = 0, free_blocks = 0; … … 432 417 } 433 418 434 #if 0435 419 /***************************************************************** 436 420 * … … 485 469 { 486 470 omBin s_bin; 487 omCheckBin(bin);488 471 s_bin = omGetStickyBin(bin, sticky_tag); 489 472 … … 506 489 } 507 490 508 void omUn setStickyBinTag(omBin bin, unsigned long sticky)491 void omUnSetStickyBinTag(omBin bin, unsigned long sticky) 509 492 { 510 493 omAssume(omGetStickyBin(bin, 0) != NULL); … … 515 498 static void omMergeStickyPages(omBin to_bin, omBin from_bin) 516 499 { 500 #ifdef HAVE_OM_ASSUME 501 int length = omGListLength(to_bin->last_page, prev) + 502 omGListLength(from_bin->last_page, prev); 503 #endif 504 517 505 omBinPage page = from_bin->last_page; 506 omAssume(to_bin->sticky == 0); 507 omAssume(to_bin->sizeW == from_bin->sizeW); 508 omAssume(to_bin != from_bin); 509 omAssume(omIsOnGList(to_bin->next, next, from_bin) 510 || 511 omIsOnGList(from_bin->next, next, to_bin)); 518 512 519 513 if (page == NULL) return; … … 528 522 if (to_bin->last_page == NULL) 529 523 { 524 omAssume(to_bin->current_page == om_ZeroPage); 530 525 to_bin->last_page = from_bin->last_page; 531 526 to_bin->current_page = from_bin->current_page; … … 533 528 } 534 529 530 omAssume(to_bin->current_page != om_ZeroPage && 531 to_bin->current_page != NULL); 532 535 533 if (to_bin->current_page->current != NULL) 536 534 { … … 544 542 to_bin->current_page = to_bin->current_page->prev; 545 543 } 546 547 if (to_bin->current_page->prev != NULL) 548 { 549 to_bin->current_page->prev->next = page; 550 page->prev = to_bin->current_page->prev; 551 } 552 from_bin->last_page->next = to_bin->current_page; 553 to_bin->current_page->prev = from_bin->last_page; 544 else 545 { 546 /* need to reset this here, since new current_page is going to be 547 from_bin->current_page, and only for current_page may we have 548 used_blocks != 0 && current == NULL */ 549 to_bin->current_page->used_blocks = 0; 550 } 551 552 553 omAssume(to_bin->current_page != NULL && 554 to_bin->current_page->current == NULL && 555 to_bin->current_page->used_blocks == 0); 556 557 from_bin->last_page->next = to_bin->current_page->next; 558 if (to_bin->current_page->next != NULL) 559 to_bin->current_page->next->prev = from_bin->last_page; 560 else 561 { 562 omAssume(to_bin->current_page == to_bin->last_page); 563 to_bin->last_page = from_bin->last_page; 564 } 565 to_bin->current_page->next = page; 566 page->prev = to_bin->current_page; 554 567 to_bin->current_page = from_bin->current_page; 555 } 568 569 #ifdef HAVE_OM_ASSUME 570 omAssume(omGListLength(to_bin->last_page, prev) == length); 571 #endif 572 } 573 574 #include "omDebug.h" 556 575 557 576 void omDeleteStickyBinTag(omBin bin, unsigned long sticky) … … 559 578 omBin no_sticky_bin = NULL; 560 579 omBin sticky_bin = NULL; 561 580 581 omdCheckBin(bin, 10); 562 582 if (sticky == 0) 563 583 { … … 566 586 } 567 587 568 omCheckBin(bin);569 570 588 sticky_bin = omGetStickyBin(bin, sticky); 571 589 if (sticky_bin != NULL) … … 575 593 576 594 omMergeStickyPages(no_sticky_bin, sticky_bin); 577 omCheckBin(no_sticky_bin);578 595 579 596 if (bin == sticky_bin) … … 585 602 FreeSizeOf(sticky_bin, omBin_t); 586 603 } 587 om CheckBin(bin);604 omdCheckBin(bin, 10); 588 605 } 589 606 … … 595 612 * 596 613 *****************************************************************/ 597 598 #ifdef BIN_DEBUG599 static BOOLEAN omIsKnownBin(omBin bin)600 {601 int i;602 mem_SpecBin s_bin;603 604 for (i=0; i<=MAX_BIN_INDEX; i++)605 {606 if (bin == &om_StaticBin[i]) return TRUE;607 }608 609 mem_SpecBin s_bin = om_SpecBins;610 while (s_bin != NULL)611 {612 if (s_bin->bin == bin) return TRUE;613 s_bin = s_bin->next;614 }615 return FALSE;616 }617 618 static BOOLEAN omDebugCheckAllBins(const char* fn, int l)619 {620 int i;621 mem_SpecBin s_bin = om_SpecBins;622 BOOLEAN return = TRUE;623 for (i=0; i<=MAX_BIN_INDEX; i++)624 {625 ret = ret && omDebugCheckBin(&(om_StaticBin[i]), fn, l);626 }627 while (s_bin != NULL)628 {629 ret = ret && omDebugCheckBin(s_bin->bin, fn, l);630 s_bin = s_bin->next;631 }632 return ret;633 }634 #endif635 636 637 614 unsigned long omGetNewStickyAllBinTag() 638 615 { … … 641 618 omSpecBin s_bin; 642 619 // first, find new sticky tag 643 for (i=0; i<= MAX_BIN_INDEX; i++)620 for (i=0; i<=OM_MAX_BIN_INDEX; i++) 644 621 { 645 622 new_sticky = omGetMaxStickyBinTag(&(om_StaticBin[i])); 646 623 if (new_sticky > sticky) sticky = new_sticky; 647 624 } 625 s_bin = om_SpecBin; 648 626 while (s_bin != NULL) 649 627 { … … 655 633 { 656 634 sticky++; 657 for (i=0; i<= MAX_BIN_INDEX; i++)635 for (i=0; i<=OM_MAX_BIN_INDEX; i++) 658 636 { 659 637 omCreateStickyBin(&(om_StaticBin[i]), sticky); … … 671 649 omBin bin; 672 650 omAssume(sticky == BIT_SIZEOF_LONG - 1); 673 for (i=0; i<= MAX_BIN_INDEX; i++)651 for (i=0; i<=OM_MAX_BIN_INDEX; i++) 674 652 { 675 653 bin = &om_StaticBin[i]; … … 692 670 omSpecBin s_bin = om_SpecBin; 693 671 int i; 694 for (i=0; i<= MAX_BIN_INDEX; i++)672 for (i=0; i<=OM_MAX_BIN_INDEX; i++) 695 673 { 696 674 omSetStickyBinTag(&(om_StaticBin[i]), sticky); … … 707 685 omSpecBin s_bin = om_SpecBin; 708 686 int i; 709 for (i=0; i<= MAX_BIN_INDEX; i++)687 for (i=0; i<=OM_MAX_BIN_INDEX; i++) 710 688 { 711 689 omUnSetStickyBinTag(&(om_StaticBin[i]), sticky); … … 722 700 omSpecBin s_bin = om_SpecBin; 723 701 int i; 724 for (i=0; i<= MAX_BIN_INDEX; i++)702 for (i=0; i<=OM_MAX_BIN_INDEX; i++) 725 703 { 726 704 omDeleteStickyBinTag(&(om_StaticBin[i]), sticky); … … 733 711 } 734 712 735 #endif736 737 713 #endif /* OM_ALLOC_C */
Note: See TracChangeset
for help on using the changeset viewer.