pallocator.T 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file pallocator.T
  10. * @author drose
  11. * @date 2001-06-05
  12. */
  13. template<class Type>
  14. INLINE pallocator_single<Type>::
  15. pallocator_single(TypeHandle type_handle) noexcept :
  16. _type_handle(type_handle)
  17. {
  18. }
  19. template<class Type>
  20. INLINE Type *pallocator_single<Type>::
  21. allocate(typename pallocator_single<Type>::size_type n, typename std::allocator<void>::const_pointer) {
  22. TAU_PROFILE("pallocator_single:allocate()", " ", TAU_USER);
  23. // This doesn't support allocating arrays.
  24. assert(n == 1);
  25. return (Type *)ASSUME_ALIGNED(StaticDeletedChain<Type>::allocate(sizeof(Type), _type_handle),
  26. MEMORY_HOOK_ALIGNMENT);
  27. }
  28. template<class Type>
  29. INLINE void pallocator_single<Type>::
  30. deallocate(typename pallocator_single<Type>::pointer p, typename pallocator_single<Type>::size_type) {
  31. TAU_PROFILE("pallocator_single:deallocate()", " ", TAU_USER);
  32. StaticDeletedChain<Type>::deallocate(p, _type_handle);
  33. }
  34. template<class Type>
  35. INLINE pallocator_array<Type>::
  36. pallocator_array(TypeHandle type_handle) noexcept :
  37. _type_handle(type_handle)
  38. {
  39. }
  40. template<class Type>
  41. INLINE Type *pallocator_array<Type>::
  42. allocate(typename pallocator_array<Type>::size_type n, typename std::allocator<void>::const_pointer) {
  43. return (typename pallocator_array<Type>::pointer)
  44. ASSUME_ALIGNED(_type_handle.allocate_array(n * sizeof(Type)), MEMORY_HOOK_ALIGNMENT);
  45. }
  46. template<class Type>
  47. INLINE void pallocator_array<Type>::
  48. deallocate(typename pallocator_array<Type>::pointer p, typename pallocator_array<Type>::size_type) {
  49. _type_handle.deallocate_array((void *)p);
  50. }