/lib/ode/ode_source/ode/src/obstack.h

http://narutortsproject.googlecode.com/ · C++ Header · 68 lines · 21 code · 14 blank · 33 comment · 0 complexity · c5c8370b0be3075510a3d8a47612dbee MD5 · raw file

  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
  4. * All rights reserved. Email: russ@q12.org Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of EITHER: *
  8. * (1) The GNU Lesser General Public License as published by the Free *
  9. * Software Foundation; either version 2.1 of the License, or (at *
  10. * your option) any later version. The text of the GNU Lesser *
  11. * General Public License is included with this library in the *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  16. * This library is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  19. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  20. * *
  21. *************************************************************************/
  22. #ifndef _ODE_OBSTACK_H_
  23. #define _ODE_OBSTACK_H_
  24. #include "objects.h"
  25. // each obstack Arena pointer points to a block of this many bytes
  26. #define dOBSTACK_ARENA_SIZE 16384
  27. struct dObStack : public dBase {
  28. struct Arena {
  29. Arena *next; // next arena in linked list
  30. size_t used; // total number of bytes used in this arena, counting
  31. }; // this header
  32. Arena *first; // head of the arena linked list. 0 if no arenas yet
  33. Arena *last; // arena where blocks are currently being allocated
  34. // used for iterator
  35. Arena *current_arena;
  36. size_t current_ofs;
  37. dObStack();
  38. ~dObStack();
  39. void *alloc (int num_bytes);
  40. // allocate a block in the last arena, allocating a new arena if necessary.
  41. // it is a runtime error if num_bytes is larger than the arena size.
  42. void freeAll();
  43. // free all blocks in all arenas. this does not deallocate the arenas
  44. // themselves, so future alloc()s will reuse them.
  45. void *rewind();
  46. // rewind the obstack iterator, and return the address of the first
  47. // allocated block. return 0 if there are no allocated blocks.
  48. void *next (int num_bytes);
  49. // return the address of the next allocated block. 'num_bytes' is the size
  50. // of the previous block. this returns null if there are no more arenas.
  51. // the sequence of 'num_bytes' parameters passed to next() during a
  52. // traversal of the list must exactly match the parameters passed to alloc().
  53. };
  54. #endif