Example #1
0
int main() {
  int i = 1, j = 1;
  // allocate memory and check that they lie on the very same xPage
  void *pa;
  void *pb;
  while (i<1009) {
    void *addra = xMalloc(i);
    void *addrb = xMalloc(i);
    pa  = xGetPageOfAddr(addra);
    pb  = xGetPageOfAddr(addrb);
    __XMALLOC_ASSERT(pa == pb);
    xFreeBinAddr(addra);
    xFreeBinAddr(addrb);
    i++;
  }

  // allocate 5 big blocks in memory ( 1007 bytes )
  // => the first 4 are on the same page, 
  //    the fifth has to be on a different one
  void *addr[5];
  void *p[5];
  for (i = 0; i <= 4; i++) {
    addr[i] = xMalloc(1007);
    p[i]    = xGetPageOfAddr(addr[i]);
  }
  // those should all be on the same page
  for(i = 0; i < 3; i++)
    for(j = 1; j <=3; j++)
      __XMALLOC_ASSERT(p[i] = p[j]);

  // p[4] should be on a different page
  __XMALLOC_ASSERT(p[4] != p[0]);

  return 0;
}
Example #2
0
int main() {
  // alloc small memory block
  int i, j;
  for (i = 1; i <= 10 * __XMALLOC_MAX_SMALL_BLOCK_SIZE ; i++) {
    void *p  = xMalloc0(i);
    __XMALLOC_ASSERT(NULL != p);
    for (j = 0; j < i; j++)
      __XMALLOC_ASSERT(0 == *((char*)(p + j)));
    xFree(p);
  }
  return 0;
}
int main() {
  // alloc a memory block
  void *p = xAllocFromSystem(2048);
  __XMALLOC_ASSERT(NULL != p);
  
  // realloc memory from the system
  p = xReallocSizeFromSystem(p, 2048, 8192);
  __XMALLOC_ASSERT(NULL != p);

  xFreeSizeToSystem(p, 8192);

  return 0;
}
int main() {
  int numberPages = __XMALLOC_MIN_NUMBER_PAGES_PER_REGION;
  void *currPage;
  xPage page;
  // => region is set to be the xBaseRegion
  xRegion region  = xAllocNewRegion(numberPages);
  xBaseRegion = region; 
  // get some big block pages from region
  currPage  = region->initAddr;
  page      = xAllocBigBlockPagesForBin(3);
  __XMALLOC_ASSERT(page->region == region);
  __XMALLOC_ASSERT(region->numberUsedPages == 3);
  __XMALLOC_ASSERT(region->initAddr == 
      (currPage + (3 * __XMALLOC_SIZEOF_SYSTEM_PAGE)));
  
  // get 1 small block page from region
  currPage  = region->initAddr;
  page      = xAllocSmallBlockPageForBin();
  __XMALLOC_ASSERT(page->region == region);
  __XMALLOC_ASSERT(region->numberUsedPages == 4);
  __XMALLOC_ASSERT(region->initAddr == 
      (currPage + (1 * __XMALLOC_SIZEOF_SYSTEM_PAGE)));
  // get more big block pages than are left in the region
  currPage  = region->initAddr;
  page      = xAllocBigBlockPagesForBin(510);
  // page is on another region!
  __XMALLOC_ASSERT(page->region != region);
  // for the old region only the 4 pages from above should be in use
  __XMALLOC_ASSERT(region->numberUsedPages == 4);

  xFreeRegion(region);

  return 0;
}
Example #5
0
int main() {
  int i;
  // alloc small memory blocks from static bins
  for (i = 1; i < __XMALLOC_MAX_SMALL_BLOCK_SIZE; i++) {
    void *p = xMalloc(i);
    xBin bin  = xGetBinOfAddr(p);
    __XMALLOC_ASSERT(xIsStaticBin(bin) == TRUE);
    xFree(p);
  }
  // alloc new bin, which is not from the static ones
  xBin newBin = xMalloc(sizeof(xBinType));
  __XMALLOC_ASSERT(xIsStaticBin(newBin) == FALSE);

  return 0;
}
Example #6
0
int main()
{
  int i = __XMALLOC_MAX_SMALL_BLOCK_SIZE;
  for (i; i < 10 * __XMALLOC_MAX_SMALL_BLOCK_SIZE; i++)
  {
    void *p = xMalloc(i);
    __XMALLOC_ASSERT(NULL != p &&
        "xMalloc should have allocated addr != NULL.");
    xFree(p);
  }
  return 0;
}
int main() {
  int i = 1;
  void *p;
  // allocate memory and check that they lie on the very same xPage
  while (i<1009) {
    void *addr  = xMalloc(i);
    p           = xGetPageOfAddr(addr);
    __XMALLOC_ASSERT(xGetBinOfAddr(addr) == xGetBinOfPage((xPage) p));
    xFreeBinAddr(addr);
    i++;
  }
  return 0;
}
int main() {
  // alloc small memory block
  void *p = xMalloc(1);
  int i;
  // reallocate the memory as long as the reallocated block size fits in
  // xmallocs bins
  for (i = 2; i < __XMALLOC_MAX_SMALL_BLOCK_SIZE; i++) {
    p = xrealloc(p,i);
    __XMALLOC_ASSERT(NULL != p &&
        "xRealloc should have allocated addr != NULL.");
  }
  xFree(p);
  return 0;
}
int main() {
  
  // preparation
  void *p         = xVallocFromSystem(512 * __XMALLOC_SIZEOF_SYSTEM_PAGE);
  
  // registration
  xRegisterPagesInRegion(p, 512);

  // check
  char *q = (char*)p + 511 * __XMALLOC_SIZEOF_SYSTEM_PAGE;
  // startIndex < endIndex
  unsigned long startIndex  = xGetPageIndexOfAddr(p);
  unsigned long endIndex    = xGetPageIndexOfAddr(q);
  unsigned long shift       = xGetPageShiftOfAddr(p);
  
  for (shift = startIndex + 1; shift < endIndex; shift++)
    __XMALLOC_ASSERT(xPageShifts[shift - xMinPageIndex] == ULONG_MAX);

  __XMALLOC_ASSERT(xMinPageIndex < xMaxPageIndex);

  xVfreeToSystem(p, 512 * __XMALLOC_SIZEOF_SYSTEM_PAGE);

  return 0;
}
Example #10
0
int main() {
  
  // alloc large memory block
  void *p = xMalloc0(2 * __XMALLOC_SIZEOF_PAGE);
  
  // realloc large
  p = xRealloc0Large(p, __XMALLOC_SIZEOF_PAGE);
  __XMALLOC_ASSERT(NULL != p);
  __XMALLOC_ASSERT(0 == *(char *)p);
  __XMALLOC_ASSERT(0 == *((char *)p + __XMALLOC_SIZEOF_PAGE -1));

  // realloc large again
  p = xRealloc0Large(p, 10 * __XMALLOC_SIZEOF_PAGE);
  __XMALLOC_ASSERT(NULL != p);
  __XMALLOC_ASSERT(0 == *(char *)p);
  __XMALLOC_ASSERT(0 == *((char *)p + __XMALLOC_SIZEOF_PAGE -1));
  __XMALLOC_ASSERT(0 == *((char *)p + (10 * __XMALLOC_SIZEOF_PAGE) -1));

  xFree(p);

  return 0;
}
Example #11
0
int main() {
  xRegion region1 = xMalloc(sizeof(xRegionType));
  __XMALLOC_ASSERT(region1->next == NULL);
  __XMALLOC_ASSERT(region1->prev == NULL);

  xRegion region2 = xMalloc(sizeof(xRegionType));
  __XMALLOC_ASSERT(region2->next == NULL);
  __XMALLOC_ASSERT(region2->prev == NULL);
  
  xRegion region3 = xMalloc(sizeof(xRegionType));
  __XMALLOC_ASSERT(region3->next == NULL);
  __XMALLOC_ASSERT(region3->prev == NULL);
  
  // inserts region1 after region2
  xInsertRegionAfter(region1, region2);
  __XMALLOC_ASSERT(region2->next == region1);
  __XMALLOC_ASSERT(region1->prev == region2);

  // inserts region3 after region2
  xInsertRegionAfter(region3, region2);
  __XMALLOC_ASSERT(region2->next == region3);
  __XMALLOC_ASSERT(region3->prev == region2);
  __XMALLOC_ASSERT(region1->prev == region3);
  __XMALLOC_ASSERT(region3->next == region1);

  xFree(region1);
  xFree(region2);
  xFree(region3);

  return 0;
}