#include <blockpool.h>
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 |
These blocks contain the memory "chunks" allocated by the pooled memory allocator.
Definition at line 68 of file blockpool.h.
|
Definition at line 87 of file blockpool.h. References GetSysInfo().
00087 { GetSysInfo(); } |
|
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 */ |
|
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 } |
|
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 |
|
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 |
|
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 |
|
Definition at line 71 of file blockpool.h. Referenced by get_info(), GetSysInfo(), and MemoryAlloc(). |
|
Definition at line 70 of file blockpool.h. Referenced by get_info(), GetSysInfo(), and MemoryAlloc(). |