Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.5 KiB

  1. /**************************************************************************
  2. * *
  3. * Copyright (C) 1992, Silicon Graphics, Inc. *
  4. * *
  5. * These coded instructions, statements, and computer programs contain *
  6. * unpublished proprietary information of Silicon Graphics, Inc., and *
  7. * are protected by Federal copyright law. They may not be disclosed *
  8. * to third parties or copied or duplicated in any form, in whole or *
  9. * in part, without the prior written consent of Silicon Graphics, Inc. *
  10. * *
  11. **************************************************************************/
  12. /*
  13. * bufpool.c++ - $Revision: 1.4 $
  14. * Derrick Burns - 1991
  15. */
  16. #include "glimport.h"
  17. #include "myassert.h"
  18. #include "bufpool.h"
  19. /*-----------------------------------------------------------------------------
  20. * Pool - allocate a new pool of buffers
  21. *-----------------------------------------------------------------------------
  22. */
  23. Pool::Pool( int _buffersize, int initpoolsize, char *n )
  24. {
  25. buffersize= (_buffersize < sizeof(Buffer)) ? sizeof(Buffer) : _buffersize;
  26. initsize = initpoolsize * buffersize;
  27. nextsize = initsize;
  28. name = n;
  29. magic = is_allocated;
  30. nextblock = 0;
  31. curblock = 0;
  32. freelist = 0;
  33. nextfree = 0;
  34. }
  35. /*-----------------------------------------------------------------------------
  36. * ~Pool - free a pool of buffers and the pool itself
  37. *-----------------------------------------------------------------------------
  38. */
  39. Pool::~Pool( void )
  40. {
  41. assert( (this != 0) && (magic == is_allocated) );
  42. while( nextblock ) {
  43. delete blocklist[--nextblock];
  44. blocklist[nextblock] = 0;
  45. }
  46. magic = is_free;
  47. }
  48. void Pool::grow( void )
  49. {
  50. assert( (this != 0) && (magic == is_allocated) );
  51. curblock = new char[nextsize];
  52. blocklist[nextblock++] = curblock;
  53. nextfree = nextsize;
  54. nextsize *= 2;
  55. }
  56. /*-----------------------------------------------------------------------------
  57. * Pool::clear - free buffers associated with pool but keep pool
  58. *-----------------------------------------------------------------------------
  59. */
  60. void
  61. Pool::clear( void )
  62. {
  63. assert( (this != 0) && (magic == is_allocated) );
  64. while( nextblock ) {
  65. delete blocklist[--nextblock];
  66. blocklist[nextblock] = 0;
  67. }
  68. curblock = 0;
  69. freelist = 0;
  70. nextfree = 0;
  71. if( nextsize > initsize )
  72. nextsize /= 2;
  73. }