Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

MemMan.cpp

Go to the documentation of this file.
00001 /*
00002 This product contains certain software code or other information
00003 ("AT&T Software") proprietary to AT&T Corp. ("AT&T").  The AT&T
00004 Software is provided to you "AS IS".  YOU ASSUME TOTAL RESPONSIBILITY
00005 AND RISK FOR USE OF THE AT&T SOFTWARE.  AT&T DOES NOT MAKE, AND
00006 EXPRESSLY DISCLAIMS, ANY EXPRESS OR IMPLIED WARRANTIES OF ANY KIND
00007 WHATSOEVER, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00008 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WARRANTIES OF
00009 TITLE OR NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS, ANY
00010 WARRANTIES ARISING BY USAGE OF TRADE, COURSE OF DEALING OR COURSE OF
00011 PERFORMANCE, OR ANY WARRANTY THAT THE AT&T SOFTWARE IS "ERROR FREE" OR
00012 WILL MEET YOUR REQUIREMENTS.
00013 
00014 Unless you accept a license to use the AT&T Software, you shall not
00015 reverse compile, disassemble or otherwise reverse engineer this
00016 product to ascertain the source code for any AT&T Software.
00017 
00018 (c) AT&T Corp. All rights reserved.  AT&T is a registered trademark of AT&T Corp.
00019 
00020 ***********************************************************************
00021 
00022 History:
00023 
00024       24/11/99  - initial release by Hartmut Liefke, liefke@seas.upenn.edu
00025                                      Dan Suciu,      suciu@research.att.com
00026 */
00027 
00028 //**************************************************************************
00029 //**************************************************************************
00030 
00031 // This module contains several auxiliary function for the
00032 // memory management
00033 
00034 #include <stdlib.h>
00035 
00036 #include "MemMan.hpp"
00037 
00038 unsigned long  allocatedmemory=0;
00039 
00040 unsigned long blocksizes[BLOCKSIZE_NUM]=
00041 {TINYBLOCK_SIZE,SMALLBLOCK_SIZE,MEDIUMBLOCK_SIZE,LARGEBLOCK_SIZE};
00042    // For each possible block size,
00043    // we store the size
00044 
00045 char *freeblocklists[BLOCKSIZE_NUM]={NULL,NULL,NULL,NULL};
00046    // For each possible block size,
00047    // we store the list of free blocks
00048 
00049 // The memory management for large blocks
00050 
00051 char *AllocateBlockRecurs(unsigned char blocksizeidx)
00052    // Allocates a new large block recursively
00053    // I.e. if there is no block in the free list, we try to allocate
00054    // a block of the next higher size
00055 {
00056    char *ptr;
00057 
00058    // Do we have any free block?
00059    if(freeblocklists[blocksizeidx]!=NULL)
00060    {
00061       ptr=freeblocklists[blocksizeidx];
00062       freeblocklists[blocksizeidx]=*(char **)freeblocklists[blocksizeidx];
00063       return ptr;
00064    }
00065    else
00066    {
00067       if(blocksizeidx==BLOCKSIZE_NUM-1)
00068          // Is this the largest possible block size??
00069          // We must allocate new space!
00070       {
00071          ptr=(char *)malloc(blocksizes[blocksizeidx]);
00072          if(ptr==NULL)
00073             ExitNoMem();
00074 
00075          return ptr;
00076       }
00077       else  // If we haven't reached the largest possible block size,
00078             // We allocate a block of the next larger block size
00079             // and use it as a container for our blocks
00080       {
00081          ptr=AllocateBlockRecurs(blocksizeidx+1);
00082 
00083          // We add the new blocks to the free list
00084          char  *ptr1=ptr+blocksizes[blocksizeidx],
00085                *endptr=ptr+blocksizes[blocksizeidx+1];
00086 
00087          do
00088          {
00089             *(char **)ptr1=freeblocklists[blocksizeidx];
00090             freeblocklists[blocksizeidx]=ptr1;
00091 
00092             ptr1+=blocksizes[blocksizeidx];
00093          }
00094          while(ptr1<endptr);
00095 
00096          return ptr;
00097       }
00098    }
00099 }

Generated on Sat Oct 13 16:08:39 2001 for XMILL by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001