Changeset e36e3a in git


Ignore:
Timestamp:
Nov 23, 1999, 9:40:13 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
Children:
d47e6fd256e2e97a44cc9bae4b289a40732b3e98
Parents:
3b8058716b41cc9477cc0c90c845072db5c5e702
Message:
* ..


git-svn-id: file:///usr/local/Singular/svn/trunk@3903 2c84dea3-7e68-4137-9b89-c4e89433aadc
Location:
omalloc
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • omalloc/Makefile.in

    r3b8058 re36e3a  
    44### Author:  obachman@mathematik.uni-kl.de (Olaf Bachmann)
    55### Created: 11/99
    6 ### Version: $Id: Makefile.in,v 1.1.1.1 1999-11-18 17:45:53 obachman Exp $
     6### Version: $Id: Makefile.in,v 1.2 1999-11-23 20:40:11 obachman Exp $
    77#################################################################
    88
     
    4747# normal C source files
    4848CSOURCES=omAlloc.c omList.c  omDebug.c omPage.c omLocal.c omFindExec.c \
    49          omTrack.c gmalloc.c
     49         omTrack.c omCheck.c gmalloc.c
    5050
    5151SOURCES=${CSOURCES}
  • omalloc/omAlloc.c

    r3b8058 re36e3a  
    44 *  Author:  obachman@mathematik.uni-kl.de (Olaf Bachmann)
    55 *  Created: 11/99
    6  *  Version: $Id: omAlloc.c,v 1.2 1999-11-22 18:12:57 obachman Exp $
     6 *  Version: $Id: omAlloc.c,v 1.3 1999-11-23 20:40:12 obachman Exp $
    77 *******************************************************************/
    88#ifndef OM_ALLOC_C
     
    1616#include "omList.h"
    1717
     18
     19/*******************************************************************
     20 * 
     21 *  global variables
     22 * 
     23 *******************************************************************/
    1824
    1925omBinPage_t om_ZeroPage[] = {{0, NULL, NULL, NULL, NULL}};
     
    2430omSpecBin om_SpecBin = NULL;
    2531
    26 
    27 #include <stdlib.h>
     32/*******************************************************************
     33 * 
     34 *  Alloc routines which we do not define as macros
     35 * 
     36 *******************************************************************/
     37void* _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
     69void* _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     
     79void* _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
     110void* _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
     120void* _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
     173void* _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 */
    28235#define AllocSizeOf(x) _omAllocBlock(sizeof(x))
    29236#define FreeSizeOf(addr, x) _omFreeBin(addr)
     
    572779}
    573780
    574 #include "omDebug.h"
    575  
    576781void omDeleteStickyBinTag(omBin bin, unsigned long sticky)
    577782{
     
    579784  omBin sticky_bin = NULL;
    580785
    581   omdCheckBin(bin, 10);
    582786  if (sticky == 0)
    583787  {
     
    602806    FreeSizeOf(sticky_bin, omBin_t);
    603807  }
    604   omdCheckBin(bin, 10);
    605808}
    606809
  • omalloc/omPrivate.h

    r3b8058 re36e3a  
    55 *  Author:  obachman (Olaf Bachmann)
    66 *  Created: 11/99
    7  *  Version: $Id: omPrivate.h,v 1.2 1999-11-22 18:12:59 obachman Exp $
     7 *  Version: $Id: omPrivate.h,v 1.3 1999-11-23 20:40:13 obachman Exp $
    88 *******************************************************************/
    99#ifndef OM_PRIVATE_H
     
    5757  long          used_blocks;    /* number of used blocks of this page */
    5858  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 with
    62                                   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*/
    6363};
     64
    6465/* Change this appropriately, if you change omBinPage           */
    6566/* However, make sure that omBinPage is a multiple of SIZEOF_MAX_TYPE */
     
    7374struct omBin_s
    7475{
    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 */
    7879  long          sizeW;          /* size in words */
    7980  long          max_blocks;     /* if > 0   # blocks in one page,
     
    8586{
    8687  omSpecBin        next;       /* pointer to next bin */
    87   omBin            bin;       /* pointer to bin itself */
     88  omBin            bin;        /* pointer to bin itself */
    8889  long             max_blocks; /* max_blocks of bin*/
    8990  long             ref;        /* ref count */
     
    176177/*******************************************************************/
    177178/* 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)
    180182
    181183#define omAllocLargeBlock(size)       OM_MALLOC(size)
     
    213215while (0)
    214216
     217#ifdef OM_ALIGNMENT_NEEDS_WORK
     218#define __omTypeAllocAlignedBlock(type, addr, size) \
     219do                                                  \
     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}                                                   \
     231while(0)
     232
     233#define __omTypeAlloc0AlignedBlock(type, addr, size)    \
     234do                                                      \
     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}                                                       \
     247while (0)
     248
     249#else /* ! OM_ALIGNMENT_NEEDS_WORK */
     250#define __omTypeAllocAlignedBlock  __omTypeAllocBlock
     251#define __omTypeAlloc0AlignedBlock __omTypeAlloc0Block
     252#endif /* OM_ALIGNMENT_NEEDS_WORK */
     253     
    215254#define __omFreeBlock(addr, size)               \
    216255do                                              \
     
    239278  if (__om_size <= OM_MAX_BLOCK_SIZE)                       \
    240279  {                                                         \
    241     omBin __om_bin = omSmallSize2Bin(__om_size);                 \
     280    omBin __om_bin = omSmallSize2Bin(__om_size);            \
    242281    __omTypeAllocBin(void*, __om_addr, __om_bin);           \
    243282    *((void**) __om_addr) = (void*) __om_bin->current_page; \
     
    246285  {                                                         \
    247286    __om_addr = omAllocLargeChunk(__om_size);               \
    248     *((void**) __om_addr) = om_LargePage;                   \
     287    *((void**) __om_addr) = (void*) om_LargePage;           \
    249288  }                                                         \
    250289  addr = (type) (__om_addr + SIZEOF_OM_ALIGNMENT);          \
     
    267306    __om_addr = omAllocLargeChunk(__om_size);               \
    268307    memset(__om_addr, 0, __om_size);                        \
    269     *((void**) __om_addr) = om_LargePage;                   \
     308    *((void**) __om_addr) = (void*) om_LargePage;           \
    270309  }                                                         \
    271310  addr = (type) (__om_addr + SIZEOF_OM_ALIGNMENT);          \
    272311}                                                           \
    273312while (0)
     313
     314#ifdef OM_ALIGNMENT_NEEDS_WORK
     315
     316#define __omTypeAllocAlignedChunk(type, addr, size)         \
     317do                                                          \
     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}                                                           \
     334while (0)
     335
     336#define __omTypeAlloc0AlignedChunk(type, addr, size)        \
     337do                                                          \
     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}                                                           \
     355while (0)
     356
     357#define __omFreeAlignedChunk(addr)                              \
     358do                                                              \
     359{                                                               \
     360  void* __addr = ((void*) (addr)) - SIZEOF_OM_CHUNK_ALIGNMENT;  \
     361  omBinPage __om_page = *((omBinPage*) __addr);                 \
     362  __omFreeToPage(__addr, __om_page);                            \
     363}                                                               \
     364while (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 */
    274372
    275373#define __omFreeChunk(addr)                                 \
     
    290388#if defined(OM_INLINE)
    291389
    292 #define OM_ALLOCBIN_FUNC_WRAPPER(func)         \
    293 OM_INLINE void* _om##func (omBin bin)         \
     390#define OM_ALLOCBIN_FUNC_WRAPPER(func)          \
     391OM_INLINE void* _om##func (omBin bin)           \
    294392{                                               \
    295393  void* addr;                                   \
    296   __omType##func (void*, addr, bin);           \
     394  __omType##func (void*, addr, bin);            \
    297395  return addr;                                  \
    298396}
Note: See TracChangeset for help on using the changeset viewer.