00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 #if !defined(OPENNURBS_FSP_INC_) 00017 #define OPENNURBS_FSP_INC_ 00018 00019 class ON_CLASS ON_FixedSizePool 00020 { 00021 public: 00022 ON_FixedSizePool(); 00023 ~ON_FixedSizePool(); 00024 00025 /* 00026 Description: 00027 Create a fixed size memory pool. 00028 Parameters: 00029 sizeof_element - [in] 00030 number of bytes in each element. This parameter must be greater than zero. 00031 In general, use sizeof(element type). If you pass a "raw" number as 00032 sizeof_element, then be certain that it is the right size to insure the 00033 fields in your elements will be properly aligned. 00034 element_count_estimate - [in] (0 = good default) 00035 If you know how many elements you will need, pass that number here. 00036 It is better to slightly overestimate than to slightly underestimate. 00037 If you do not have a good estimate, then use zero. 00038 block_element_capacity - [in] (0 = good default) 00039 If block_element_capacity is zero, Create() will calculate a block 00040 size that is efficent for most applications. If you are an expert 00041 user and want to specify the number of elements per block, 00042 then pass the number of elements per block here. When 00043 block_element_capacity > 0 and element_count_estimate > 0, the first 00044 block will have a capacity of at least element_count_estimate; in this 00045 case do not ask for extraordinarly large amounts of contiguous heap. 00046 Remarks: 00047 You must call Create() on an unused ON_FixedSizePool or call Destroy() 00048 before calling create. 00049 Returns: 00050 True if successful and the pool can be used. 00051 */ 00052 bool Create( 00053 size_t sizeof_element, 00054 size_t element_count_estimate, 00055 size_t block_element_capacity 00056 ); 00057 00058 /* 00059 Returns: 00060 Size of the elements in this pool. 00061 */ 00062 size_t SizeofElement() const; 00063 00064 /* 00065 Returns: 00066 A pointer to sizeof_element bytes. The memory is zeroed. 00067 */ 00068 void* AllocateElement(); 00069 00070 /* 00071 Description: 00072 Return an element to the pool. 00073 Parameters: 00074 p - [in] 00075 A pointer returned by AllocateElement(). 00076 It is critical that p be from this pool and that 00077 you return a pointer no more than one time. 00078 Remarks: 00079 If you find the following remarks confusing, but you really want to use 00080 ReturnElement(), then here are some simple guidelines. 00081 1) SizeofElement() must be >= 16 00082 2) SizeofElement() must be a multiple of 8. 00083 3) Do not use FirstElement() and NextElement() to iterate through 00084 the pool. 00085 00086 If 1 to 3 don't work for you, then you need to understand the following 00087 information before using ReturnElement(). 00088 00089 ON_FixedMemoryPool uses the first sizeof(void*) bytes of the 00090 returned element for bookkeeping purposes. Therefore, if you 00091 are going to use ReturnElement(), then SizeofElement() must be 00092 at least sizeof(void*). If you are using a platform that requires 00093 pointers to be aligned on sizeof(void*) boundaries, then 00094 SizeofElement() must be a multiple of sizeof(void*). 00095 If you are going to use ReturnElement() and then use FirstElement() 00096 and NextElement() to iterate through the list of elements, then you 00097 need to set a value in the returned element to indicate that it 00098 needs to be skipped during the iteration. This value cannot be 00099 located in the fist sizeof(void*) bytes of the element. If the 00100 element is a class with a vtable, you cannot call a virtual 00101 function on a returned element because the vtable pointer is 00102 trashed when ReturnElement() modifies the fist sizeof(void*) bytes. 00103 */ 00104 void ReturnElement(void* p); 00105 00106 /* 00107 Description: 00108 Return all allocated elements to the pool. No heap is freed and 00109 the pool remains initialized and ready for AllocateElement() 00110 to be called. 00111 */ 00112 void ReturnAll(); 00113 00114 /* 00115 Description: 00116 Destroy the pool and free all the heap. The pool cannot be used again 00117 until Create() is called. 00118 */ 00119 void Destroy(); 00120 00121 /* 00122 Returns: 00123 Number of active elements. (Elements that have been returned are not active.) 00124 */ 00125 size_t ActiveElementCount() const; 00126 00127 /* 00128 Returns: 00129 Total number of elements = number of active elements + number of returned elements. 00130 */ 00131 size_t TotalElementCount() const; 00132 00133 /* 00134 Description: 00135 Get the first element when iterating through the list of elements. 00136 Parameters: 00137 element_index - [in] 00138 If you use the version of FirstElement() that has an 00139 element_index parameter, then the iteration begins at 00140 that element. 00141 Example: 00142 The loop will iteratate through all the elements returned from 00143 AllocateElement(), including any that have be returned to the pool 00144 using ReturnElement(). 00145 00146 // iterate through all elements in the pool 00147 // This iteration will go through TotalElements() items. 00148 for ( void* p = FirstElement(); 0 != p; p = NextElement() ) 00149 { 00150 // If you are not using ReturnElement(), then you may process 00151 // "p" immediately. If you have used ReturnElement(), then you 00152 // must check some value in p located after the first sizeof(void*) 00153 // bytes to see if p is active. 00154 if ( p is not active ) 00155 continue; 00156 00157 ... process p 00158 } 00159 00160 Returns: 00161 The first element when iterating through the list of elements. 00162 Remarks: 00163 FirstElement() and NextElement() will return elements that have 00164 been returned to the pool using ReturnElement(). If you use 00165 ReturnElement(), then be sure to mark the element so it can be 00166 identified and skipped. 00167 00168 Do not make any calls to FirstBlock() or NextBlock() when using 00169 FirstElement() and NextElement() to iteratate through elements. 00170 00171 If you need iterate through a fixed size pool and another 00172 function may also be in the middle of iterating the pool 00173 as well, then use ON_FixedSizePoolIterator. In particular, 00174 if you have multiple concurrent threads iterating the same 00175 fixed size pool, then use ON_FixedSizePoolIterator. 00176 */ 00177 void* FirstElement(); 00178 void* FirstElement( size_t element_index ); 00179 00180 /* 00181 Description: 00182 Get the next element when iterating through the list of elements. 00183 Example: 00184 See the FirstElement() documentation. 00185 Returns: 00186 The next element when iterating through the list of elements. 00187 Remarks: 00188 FirstElement() and NextElement() will return elements that have 00189 been returned to the pool using ReturnElement(). If you use 00190 ReturnElement(), then be sure to mark the element so it can be 00191 identified and skipped. 00192 00193 Do not make any calls to FirstBlock() or NextBlock() when using 00194 FirstElement() and NextElement() to iteratate through elements. 00195 00196 If you need iterate through a fixed size pool and another 00197 function may also be in the middle of iterating the pool 00198 as well, then use ON_FixedSizePoolIterator. In particular, 00199 if you have multiple concurrent threads iterating the same 00200 fixed size pool, then use ON_FixedSizePoolIterator. 00201 */ 00202 void* NextElement(); 00203 00204 /* 00205 Description: 00206 Get a pointer to the first element in the first block. 00207 Parameters: 00208 block_element_count - [out] (can be null) 00209 If not null, the number of elements allocated from the 00210 first block is returned in block_element_count. 00211 Note that if you have used ReturnElement(), some 00212 of these elemements may have been returned. 00213 Example: 00214 The loop will iteratate through all the blocks. 00215 00216 // iterate through all blocks in the pool 00217 size_t block_element_count = 0; 00218 for ( void* p = FirstBlock(&block_element_count); 00219 0 != p; 00220 p = NextBlock(&block_element_count) 00221 ) 00222 { 00223 ElementType* e = (ElementType*)p; 00224 for ( size_t i = 0; 00225 i < block_element_count; 00226 i++, e = ((const char*)e) + SizeofElement() 00227 ) 00228 { 00229 ... 00230 } 00231 } 00232 00233 Returns: 00234 The first block when iterating the list of blocks. 00235 Remarks: 00236 The heap for a fixed size memory pool is simply a linked 00237 list of blocks. FirstBlock() and NextBlock() can be used 00238 to iterate through the list of blocks. 00239 00240 Do not make any calls to FirstElement() or NextElement() when using 00241 FirstBlock() and NextBlock() to iteratate through blocks. 00242 00243 If you need iterate through a fixed size pool and another 00244 function may also be in the middle of iterating the pool 00245 as well, then use ON_FixedSizePoolIterator. In particular, 00246 if you have multiple concurrent threads iterating the same 00247 fixed size pool, then use ON_FixedSizePoolIterator. 00248 */ 00249 void* FirstBlock( size_t* block_element_count ); 00250 00251 /* 00252 Description: 00253 Get the next block when iterating through the blocks. 00254 Parameters: 00255 block_element_count - [out] (can be null) 00256 If not null, the number of elements allocated from the 00257 block is returned in block_element_count. Note that if 00258 you have used ReturnElement(), some of these elemements 00259 may have been returned. 00260 Example: 00261 See the FirstBlock() documentation. 00262 Returns: 00263 The next block when iterating through the blocks. 00264 Remarks: 00265 Do not make any calls to FirstElement() or NextElement() when using 00266 FirstBlock() and NextBlock() to iteratate through blocks. 00267 00268 If you need iterate through a fixed size pool and another 00269 function may also be in the middle of iterating the pool 00270 as well, then use ON_FixedSizePoolIterator. In particular, 00271 if you have multiple concurrent threads iterating the same 00272 fixed size pool, then use ON_FixedSizePoolIterator. 00273 */ 00274 void* NextBlock( size_t* block_element_count ); 00275 00276 /* 00277 Description: 00278 Get the i-th elment in the pool. 00279 Parameters: 00280 element_index - [in] 00281 Returns: 00282 A pointer to the i-th element. The first element has index = 0 00283 and is the element returned by the first call to AllocateElement(). 00284 The last element has index = ElementCount()-1. 00285 If i is out of range, null is returned. 00286 Remarks: 00287 It is faster to use FirstElement() and NextElement() to iterate 00288 through the entire list of elements. This function is relatively 00289 efficient when there are a few large blocks in the pool 00290 or element_index is small compared to the number of elements 00291 in the first few blocks. 00292 00293 If ReturnElement() is not used or AllocateElement() calls to 00294 are made after any use of ReturnElement(), then the i-th 00295 element is the one returned by the (i+1)-th call to 00296 AllocateElement(). 00297 */ 00298 void* Element(size_t element_index) const; 00299 00300 public: 00301 // Expert user functions below for situations where you 00302 // need to specify the heap used for this pool. 00303 00304 /* 00305 Description: 00306 Expert user function to specify which heap is used. 00307 */ 00308 void SetHeap( ON_MEMORY_POOL* heap ); 00309 00310 /* 00311 Description: 00312 Expert user function. 00313 Returns: 00314 Heap used by this pool. A null pointer means the default 00315 heap is being used. 00316 */ 00317 ON_MEMORY_POOL* Heap(); 00318 00319 /* 00320 Description: 00321 Expert user function to call when the heap used by this pool 00322 is no longer valid. This call zeros all fields and does not 00323 call any heap functions. After calling EmergencyDestroy(), 00324 the destructor will not attempt to free any heap. 00325 */ 00326 void EmergencyDestroy(); 00327 00328 private: 00329 friend class ON_FixedSizePoolIterator; 00330 00331 void* m_first_block; 00332 00333 // ReturnElement() adds to the m_al_element stack. 00334 // AllocateElement() will use the stack before using m_al_element_array[] 00335 void* m_al_element_stack; 00336 00337 // used by the iterators 00338 void* m_qwerty_it_block; 00339 void* m_qwerty_it_element; 00340 00341 void* m_al_block; // current element allocation block. 00342 // m_al_element_array[] is in m_al_block and has length m_al_count. 00343 void* m_al_element_array; 00344 size_t m_al_count; 00345 size_t m_sizeof_element; 00346 size_t m_block_element_count; // block element count 00347 size_t m_active_element_count; // number of active elements 00348 size_t m_total_element_count; // total number of elements (active + returned) 00349 ON_MEMORY_POOL* m_heap; 00350 00351 private: 00352 // returns capacity of elements in existing block 00353 size_t BlockElementCapacity( const void* block ) const; 00354 00355 // returns number of allocated of elements in existing block 00356 size_t BlockElementCount( const void* block ) const; 00357 private: 00358 // prohibit copy construction and operator=. 00359 ON_FixedSizePool(const ON_FixedSizePool&); 00360 ON_FixedSizePool& operator=(const ON_FixedSizePool&); 00361 }; 00362 00363 class ON_CLASS ON_FixedSizePoolIterator 00364 { 00365 public: 00366 ON_FixedSizePoolIterator( const class ON_FixedSizePool& fsp ); 00367 00368 const class ON_FixedSizePool& m_fsp; 00369 00370 /* 00371 Description: 00372 Get the first element when iterating through the list of elements. 00373 Parameters: 00374 element_index - [in] 00375 If you use the version of FirstElement() that has an 00376 element_index parameter, then the iteration begins at 00377 that element. 00378 Example: 00379 The loop will iteratate through all the elements returned from 00380 AllocateElement(), including any that have be returned to the pool 00381 using ReturnElement(). 00382 00383 // iterate through all elements in the pool 00384 // This iteration will go through TotalElements() items. 00385 for ( void* p = FirstElement(); 0 != p; p = NextElement() ) 00386 { 00387 // If you are not using ReturnElement(), then you may process 00388 // "p" immediately. If you have used ReturnElement(), then you 00389 // must check some value in p located after the first sizeof(void*) 00390 // bytes to see if p is active. 00391 if ( p is not active ) 00392 continue; 00393 00394 ... process p 00395 } 00396 00397 Returns: 00398 The first element when iterating through the list of elements. 00399 Remarks: 00400 FirstElement() and NextElement() will return elements that have 00401 been returned to the pool using ReturnElement(). If you use 00402 ReturnElement(), then be sure to mark the element so it can be 00403 identified and skipped. 00404 00405 Do not make any calls to FirstBlock() or NextBlock() when using 00406 FirstElement() and NextElement() to iteratate through elements. 00407 */ 00408 void* FirstElement(); 00409 void* FirstElement( size_t element_index ); 00410 00411 /* 00412 Description: 00413 Get the next element when iterating through the list of elements. 00414 Example: 00415 See the FirstElement() documentation. 00416 Returns: 00417 The next element when iterating through the list of elements. 00418 Remarks: 00419 FirstElement() and NextElement() will return elements that have 00420 been returned to the pool using ReturnElement(). If you use 00421 ReturnElement(), then be sure to mark the element so it can be 00422 identified and skipped. 00423 00424 Do not make any calls to FirstBlock() or NextBlock() when using 00425 FirstElement() and NextElement() to iteratate through elements. 00426 */ 00427 void* NextElement(); 00428 00429 /* 00430 Description: 00431 Get a pointer to the first element in the first block. 00432 Parameters: 00433 block_element_count - [out] (can be null) 00434 If not null, the number of elements allocated from the 00435 first block is returned in block_element_count. 00436 Note that if you have used ReturnElement(), some 00437 of these elemements may have been returned. 00438 Example: 00439 The loop will iteratate through all the blocks. 00440 00441 // iterate through all blocks in the pool 00442 size_t block_element_count = 0; 00443 for ( void* p = FirstBlock(&block_element_count); 00444 0 != p; 00445 p = NextBlock(&block_element_count) 00446 ) 00447 { 00448 ElementType* e = (ElementType*)p; 00449 for ( size_t i = 0; 00450 i < block_element_count; 00451 i++, e = ((const char*)e) + SizeofElement() 00452 ) 00453 { 00454 ... 00455 } 00456 } 00457 00458 Returns: 00459 The first block when iterating the list of blocks. 00460 Remarks: 00461 The heap for a fixed size memory pool is simply a linked 00462 list of blocks. FirstBlock() and NextBlock() can be used 00463 to iterate through the list of blocks. 00464 00465 Do not make any calls to FirstElement() or NextElement() when using 00466 FirstBlock() and NextBlock() to iteratate through blocks. 00467 */ 00468 void* FirstBlock( size_t* block_element_count ); 00469 00470 /* 00471 Description: 00472 Get the next block when iterating through the blocks. 00473 Parameters: 00474 block_element_count - [out] (can be null) 00475 If not null, the number of elements allocated from the 00476 block is returned in block_element_count. Note that if 00477 you have used ReturnElement(), some of these elemements 00478 may have been returned. 00479 Example: 00480 See the FirstBlock() documentation. 00481 Returns: 00482 The next block when iterating through the blocks. 00483 Remarks: 00484 Do not make any calls to FirstElement() or NextElement() when using 00485 FirstBlock() and NextBlock() to iteratate through blocks. 00486 */ 00487 void* NextBlock( size_t* block_element_count ); 00488 00489 private: 00490 void* m_it_block; 00491 void* m_it_element; 00492 00493 // no implementation (you can use a copy construtor) 00494 ON_FixedSizePoolIterator& operator=(const ON_FixedSizePoolIterator&); 00495 }; 00496 00497 00498 template <class T> class ON_SimpleFixedSizePool : private ON_FixedSizePool 00499 { 00500 public: 00501 // construction //////////////////////////////////////////////////////// 00502 00503 ON_SimpleFixedSizePool(); 00504 ~ON_SimpleFixedSizePool(); 00505 00506 /* 00507 Description: 00508 Create a fixed size memory pool. 00509 Parameters: 00510 element_count_estimate - [in] (0 = good default) 00511 If you know how many elements you will need, pass that number here. 00512 It is better to slightly overestimate than to slightly underestimate. 00513 If you do not have a good estimate, then use zero. 00514 block_element_count - [in] (0 = good default) 00515 If block_element_count is zero, Create() will calculate a block 00516 size that is efficent for most applications. If you are an expert 00517 user and want to specify the number of blocks, then pass the number 00518 of elements per block here. When block_element_count > 0 and 00519 element_count_estimate > 0, the first block will be large enough 00520 element_count_estimate*sizeof(T) bytes; in this case do not 00521 ask for extraordinarly large amounts of contiguous heap. 00522 Remarks: 00523 You must call Create() on an unused ON_FixedSizePool or call Destroy() 00524 before calling create. 00525 Returns: 00526 True if successful and the pool can be used. 00527 */ 00528 bool Create( 00529 size_t element_count_estimate, 00530 size_t block_element_count 00531 ); 00532 00533 /* 00534 Returns: 00535 Size of the elements in this pool. 00536 */ 00537 size_t SizeofElement() const; 00538 00539 /* 00540 Returns: 00541 A pointer to sizeof_element bytes. The memory is zeroed. 00542 */ 00543 T* AllocateElement(); 00544 00545 /* 00546 Description: 00547 Return an element to the pool. 00548 Parameters: 00549 p - [in] 00550 A pointer returned by AllocateElement(). 00551 It is critical that p be from this pool and that 00552 you return a pointer no more than one time. 00553 Remarks: 00554 If you find the following remarks confusing, but you really want to use 00555 ReturnElement(), then here are some simple guidelines. 00556 1) SizeofElement() must be >= 16 00557 2) SizeofElement() must be a multiple of 8. 00558 3) Do not use FirstElement() and NextElement() to iterate through 00559 the pool. 00560 00561 If 1 to 3 don't work for you, then you need to understand the following 00562 information before using ReturnElement(). 00563 00564 ON_FixedMemoryPool uses the first sizeof(void*) bytes of the 00565 returned element for bookkeeping purposes. Therefore, if you 00566 are going to use ReturnElement(), then SizeofElement() must be 00567 at least sizeof(void*). If you are using a platform that requires 00568 pointers to be aligned on sizeof(void*) boundaries, then 00569 SizeofElement() must be a multiple of sizeof(void*). 00570 If you are going to use ReturnElement() and then use FirstElement() 00571 and NextElement() to iterate through the list of elements, then you 00572 need to set a value in the returned element to indicate that it 00573 needs to be skipped during the iteration. This value cannot be 00574 located in the fist sizeof(void*) bytes of the element. If the 00575 element is a class with a vtable, you cannot call a virtual 00576 function on a returned element because the vtable pointer is 00577 trashed when ReturnElement() modifies the fist sizeof(void*) bytes. 00578 */ 00579 void ReturnElement(T* p); 00580 00581 /* 00582 Description: 00583 Return all allocated elements to the pool. No heap is freed and 00584 the pool remains initialized and ready for AllocateElement() 00585 to be called. 00586 */ 00587 void ReturnAll(); 00588 00589 /* 00590 Description: 00591 Destroy the pool and free all the heap. The pool cannot be used again 00592 until Create() is called. 00593 */ 00594 void Destroy(); 00595 00596 /* 00597 Returns: 00598 Number of active elements. (Elements that have been returned are not active.) 00599 */ 00600 size_t ActiveElementCount() const; 00601 00602 /* 00603 Returns: 00604 Total number of elements = number of active elements + number of returned elements. 00605 */ 00606 size_t TotalElementCount() const; 00607 00608 /* 00609 Description: 00610 Get the next element when iterating through the active elements. 00611 Example: 00612 The loop will iteratate through all the elements returned from 00613 AllocateElement(), including any that have be returned to the pool 00614 using ReturnElement(). 00615 00616 // iterate through all elements in the pool 00617 for ( T* p = FirstElement(); 0 != p; p = NextElement() ) 00618 { 00619 // If you are not using ReturnElement(), then you may process 00620 // "p" immediately. If you have used ReturnElement(), then you 00621 // must check some value in p located after the first sizeof(void*) 00622 // bytes to see if p is active. 00623 if ( p is not active ) 00624 continue; 00625 00626 ... process p 00627 } 00628 00629 Returns: 00630 The next element when iterating through the active elements. 00631 Remarks: 00632 NextElement() will return elements that have been returned to 00633 the pool using ReturnElement(). If you use ReturnElement(), 00634 be sure to mark the element so it can be identified and skipped. 00635 */ 00636 T* FirstElement(); 00637 00638 /* 00639 Description: 00640 Get the next element when iterating through the active elements. 00641 Example: 00642 See the FirstElement() documentation. 00643 Returns: 00644 The next element when iterating through the active elements. 00645 Remarks: 00646 NextElement() will return elements that have been returned to 00647 the pool using ReturnElement(). If you use ReturnElement(), 00648 be sure to mark the element so it can be identified and skipped. 00649 */ 00650 T* NextElement(); 00651 00652 /* 00653 Description: 00654 Get a pointer to the first element in the first block. 00655 Example: 00656 The loop will iteratate through all the blocks. 00657 00658 // iterate through all blocks in the pool 00659 size_t block_element_count = 0; 00660 for ( T* p = FirstBlock(&block_element_count); 00661 0 != p; 00662 p = NextBlock(&block_element_count) 00663 ) 00664 { 00665 // a[] is an array of length block_element_count 00666 } 00667 00668 Returns: 00669 The next block when iterating the list of blocks. 00670 Remarks: 00671 Do not make any calls to FirstElement() or NextElement() when using 00672 FirstBlock() and NextBlock() to iteratate through blocks. 00673 */ 00674 T* FirstBlock( size_t* block_element_count ); 00675 00676 /* 00677 Description: 00678 Get the next block when iterating through the blocks. 00679 Example: 00680 See the FirstBlock() documentation. 00681 Returns: 00682 The next block when iterating through the blocks. 00683 Remarks: 00684 Do not make any calls to FirstElement() or NextElement() when using 00685 FirstBlock() and NextBlock() to iteratate through blocks. 00686 */ 00687 T* NextBlock( size_t* block_element_count ); 00688 00689 00690 /* 00691 Description: 00692 Get the i-th elment in the pool. 00693 Parameters: 00694 element_index - [in] 00695 Returns: 00696 A pointer to the i-th element. The first element has index = 0 00697 and is the element returned by the first call to AllocateElement(). 00698 The last element has index = ElementCount()-1. 00699 If i is out of range, null is returned. 00700 Remarks: 00701 It is faster to use FirstElement() and NextElement() to iterate 00702 through the entire list of elements. This function is relatively 00703 efficient when there are a few large blocks in the pool 00704 or element_index is small compared to the number of elements 00705 in the first few blocks. 00706 00707 If ReturnElement() is not used or AllocateElement() calls to 00708 are made after any use of ReturnElement(), then the i-th 00709 element is the one returned by the (i+1)-th call to 00710 AllocateElement(). 00711 */ 00712 T* Element(size_t element_index) const; 00713 00714 public: 00715 // Expert user functions below for situations where you 00716 // need to specify the heap used for this pool. 00717 00718 /* 00719 Description: 00720 Expert user function to specify which heap is used. 00721 */ 00722 void SetHeap( ON_MEMORY_POOL* heap ); 00723 00724 /* 00725 Description: 00726 Expert user function. 00727 Returns: 00728 Heap used by this pool. A null pointer means the default 00729 heap is being used. 00730 */ 00731 ON_MEMORY_POOL* Heap(); 00732 00733 /* 00734 Description: 00735 Expert user function to call when the heap used by this pool 00736 is no longer valid. This call zeros all fields and does not 00737 call any heap functions. After calling EmergencyDestroy(), 00738 the destructor will not attempt to free any heap. 00739 */ 00740 void EmergencyDestroy(); 00741 00742 private: 00743 // prohibit copy construction and operator=. 00744 ON_SimpleFixedSizePool(const ON_SimpleFixedSizePool<T>&); 00745 ON_SimpleFixedSizePool<T>& operator=(const ON_SimpleFixedSizePool<T>&); 00746 }; 00747 00748 // definitions of the template functions are in a different file 00749 // so that Microsoft's developer studio's autocomplete utility 00750 // will work on the template functions. 00751 #include "opennurbs_fsp_defs.h" 00752 00753 #endif 00754