Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbufpool.h
Go to the documentation of this file.
00001 /* 00002 ** License Applicability. Except to the extent portions of this file are 00003 ** made subject to an alternative license as permitted in the SGI Free 00004 ** Software License B, Version 1.1 (the "License"), the contents of this 00005 ** file are subject only to the provisions of the License. You may not use 00006 ** this file except in compliance with the License. You may obtain a copy 00007 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 00008 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 00009 ** 00010 ** http://oss.sgi.com/projects/FreeB 00011 ** 00012 ** Note that, as provided in the License, the Software is distributed on an 00013 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 00014 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 00015 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 00016 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 00017 ** 00018 ** Original Code. The Original Code is: OpenGL Sample Implementation, 00019 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 00020 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 00021 ** Copyright in any portions created by third parties is as indicated 00022 ** elsewhere herein. All Rights Reserved. 00023 ** 00024 ** Additional Notice Provisions: The application programming interfaces 00025 ** established by SGI in conjunction with the Original Code are The 00026 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released 00027 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version 00028 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X 00029 ** Window System(R) (Version 1.3), released October 19, 1998. This software 00030 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation 00031 ** published by SGI, but has not been independently verified as being 00032 ** compliant with the OpenGL(R) version 1.2.1 Specification. 00033 */ 00034 00035 /* 00036 * bufpool.h 00037 * 00038 * $Date: 2009-08-30 15:53:16 +0000 (Sun, 30 Aug 2009) $ $Revision: 1.1 $ 00039 * $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/glu32/libnurbs/internals/bufpool.h,v 1.1 2004/02/02 16:39:11 navaraf Exp $ 00040 */ 00041 00042 #ifndef __glubufpool_h_ 00043 #define __glubufpool_h_ 00044 00045 #include "gluos.h" 00046 #include "myassert.h" 00047 #include "mystdlib.h" 00048 00049 #define NBLOCKS 32 00050 00051 class Buffer { 00052 friend class Pool; 00053 Buffer * next; /* next buffer on free list */ 00054 }; 00055 00056 class Pool { 00057 public: 00058 Pool( int, int, const char * ); 00059 ~Pool( void ); 00060 inline void* new_buffer( void ); 00061 inline void free_buffer( void * ); 00062 void clear( void ); 00063 00064 private: 00065 void grow( void ); 00066 00067 protected: 00068 Buffer *freelist; /* linked list of free buffers */ 00069 char *blocklist[NBLOCKS]; /* blocks of malloced memory */ 00070 int nextblock; /* next free block index */ 00071 char *curblock; /* last malloced block */ 00072 int buffersize; /* bytes per buffer */ 00073 int nextsize; /* size of next block of memory */ 00074 int nextfree; /* byte offset past next free buffer */ 00075 int initsize; 00076 enum Magic { is_allocated = 0xf3a1, is_free = 0xf1a2 }; 00077 const char *name; /* name of the pool */ 00078 Magic magic; /* marker for valid pool */ 00079 }; 00080 00081 /*----------------------------------------------------------------------------- 00082 * Pool::free_buffer - return a buffer to a pool 00083 *----------------------------------------------------------------------------- 00084 */ 00085 00086 inline void 00087 Pool::free_buffer( void *b ) 00088 { 00089 assert( (this != 0) && (magic == is_allocated) ); 00090 00091 /* add buffer to singly connected free list */ 00092 00093 ((Buffer *) b)->next = freelist; 00094 freelist = (Buffer *) b; 00095 } 00096 00097 00098 /*----------------------------------------------------------------------------- 00099 * Pool::new_buffer - allocate a buffer from a pool 00100 *----------------------------------------------------------------------------- 00101 */ 00102 00103 inline void * 00104 Pool::new_buffer( void ) 00105 { 00106 void *buffer; 00107 00108 assert( (this != 0) && (magic == is_allocated) ); 00109 00110 /* find free buffer */ 00111 00112 if( freelist ) { 00113 buffer = (void *) freelist; 00114 freelist = freelist->next; 00115 } else { 00116 if( ! nextfree ) 00117 grow( ); 00118 nextfree -= buffersize; 00119 buffer = (void *) (curblock + nextfree); 00120 } 00121 return buffer; 00122 } 00123 00124 class PooledObj { 00125 public: 00126 inline void * operator new( size_t, Pool & ); 00127 inline void * operator new( size_t, void *); 00128 inline void * operator new( size_t s) 00129 { return ::new char[s]; } 00130 inline void operator delete( void * ) { assert( 0 ); } 00131 inline void deleteMe( Pool & ); 00132 }; 00133 00134 inline void * 00135 PooledObj::operator new( size_t, Pool& pool ) 00136 { 00137 return pool.new_buffer(); 00138 } 00139 00140 inline void 00141 PooledObj::deleteMe( Pool& pool ) 00142 { 00143 pool.free_buffer( (void *) this ); 00144 } 00145 00146 #endif /* __glubufpool_h_ */ Generated on Sun May 27 2012 04:23:39 for ReactOS by
1.7.6.1
|