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

big_block_alloc Class Reference

Support for the allocation of large memory blocks. More...

#include <blockpool.h>

List of all members.

Public Member Functions

void get_info (unsigned int &pg_size, unsigned int &gran)
void * MemoryAlloc (unsigned int num_bytes)
 Allocate memory from the virtual memory pool.

void MemoryFree (void *address)
 Free large memory blocks.

 big_block_alloc (void)

Private Member Functions

void GetSysInfo (void)
 This is a system dependent function that returns the system virtual memory page size and the allocation granularity.

void alloc_error (void)

Private Attributes

unsigned int page_size
unsigned int alloc_gran


Detailed Description

Support for the allocation of large memory blocks.

These blocks contain the memory "chunks" allocated by the pooled memory allocator.

Definition at line 68 of file blockpool.h.


Constructor & Destructor Documentation

big_block_alloc::big_block_alloc void   )  [inline]
 

Definition at line 87 of file blockpool.h.

References GetSysInfo().

00087 { GetSysInfo(); }


Member Function Documentation

void big_block_alloc::alloc_error void   )  [private]
 

Definition at line 49 of file bigblock.C.

Referenced by MemoryAlloc(), and MemoryFree().

00050 {
00051   printf("big_block_alloc: memory allocation error\n");
00052   exit( 1 );
00053 } /* big_block_alloc::alloc_error */

void big_block_alloc::get_info unsigned int &  pg_size,
unsigned int &  gran
[inline]
 

Definition at line 78 of file blockpool.h.

References alloc_gran, and page_size.

Referenced by big_block_pool::getinfo().

00079   {
00080     assert((page_size != 0 && alloc_gran != 0));
00081     
00082     pg_size = page_size;
00083     gran = alloc_gran;
00084   }

void big_block_alloc::GetSysInfo void   )  [private]
 

This is a system dependent function that returns the system virtual memory page size and the allocation granularity.

The Allocation granularity is the smallest allocatable block of virtual memory. On UNIX systems this tends to be the same as the value returned by getpagesize(). On Win32 systems the allocation granularity is usually larger than the page size.

Definition at line 132 of file bigblock.C.

References alloc_gran, getpagesize(), and page_size.

Referenced by big_block_alloc().

00133 {
00134 
00135 #ifdef _UNIX_
00139   const int page_multiple = 4;
00140 
00141   page_size = getpagesize();
00142   // on HP-UX 9.0 use page_size = (unsigned int)sysconf( _SC_PAGE_SIZE );
00143   alloc_gran = page_size * page_multiple;
00144 
00145 #else
00149   
00150   SYSTEM_INFO sys_info;  // system info structure, defined in windows.h
00151 
00152   GetSystemInfo( &sys_info );
00153   page_size = sys_info.dwPageSize;
00154   alloc_gran = sys_info.dwAllocationGranularity;
00155 
00156 #endif
00157   assert( page_size != 0 );
00158   assert( alloc_gran != 0 );
00159 } // big_block_alloc::GetSysInfo

void * big_block_alloc::MemoryAlloc unsigned int  num_bytes  ) 
 

Allocate memory from the virtual memory pool.

This block should be an integral number of pages and should be greater than or equal to the allocation granularity.

Definition at line 62 of file bigblock.C.

References alloc_error(), alloc_gran, NULL, and page_size.

Referenced by big_block_pool::MemAlloc().

00063 {
00064   void *mem;
00065 
00066   assert( num_bytes >= alloc_gran );  
00067   assert( num_bytes % page_size == 0 );  // should be an integral number of pages
00068 
00069 #ifdef _UNIX_
00073   mem = (void *)malloc( num_bytes );
00074   if (mem != NULL) { // zero out the memory
00075     memset(mem, 0, num_bytes);
00076   }
00077 
00078 #else
00082 
00083   // Call the Win32 virtual memory allocater.  Virtual blocks are always
00084   // zeroed out (see Microsoft documentation on VirtualAlloc).
00085   mem = VirtualAlloc(NULL, num_bytes, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE );
00086 #endif
00087 
00088   if (mem == NULL)
00089     alloc_error();
00090 
00091   return mem;
00092 } // big_block_alloc::MemoryAlloc

void big_block_alloc::MemoryFree void *  address  ) 
 

Free large memory blocks.

Definition at line 99 of file bigblock.C.

References alloc_error().

Referenced by big_block_pool::MemFree().

00100 {
00101 
00102 #ifdef _UNIX_
00106 
00107   free( address );
00108 
00109 #else
00113 
00114   if (! VirtualFree(address, 0, MEM_RELEASE))
00115     alloc_error();
00116 
00117 #endif
00118 
00119 } // big_block_alloc::MemoryFree


Member Data Documentation

unsigned int big_block_alloc::alloc_gran [private]
 

Definition at line 71 of file blockpool.h.

Referenced by get_info(), GetSysInfo(), and MemoryAlloc().

unsigned int big_block_alloc::page_size [private]
 

Definition at line 70 of file blockpool.h.

Referenced by get_info(), GetSysInfo(), and MemoryAlloc().


The documentation for this class was generated from the following files:
Generated on Wed Mar 31 21:16:05 2004 for Data Structures for a VHDL Compiler by doxygen 1.3.3