General Purpose library for Freestanding C++ and POSIX systems
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.

63 lines
1.4 KiB

3 years ago
  1. #pragma once
  2. #include "gp_config.hpp"
  3. #include "gp/algorithm/move.hpp"
  4. #include "gp/allocator/allocator.hpp"
  5. #include "gp/exception.hpp"
  6. #include <type_traits>
  7. // XXX: THIS FILE SHOULD BE REMOVED, AS SHOULD ALL DEPENDENCIES ON THE C-ALLOCATOR AS IS
  8. /*
  9. namespace gp{
  10. template<class T, typename I = std::enable_if_t<gp_config::memory_module::is_ok,int>>
  11. class default_memory_allocator
  12. {
  13. public:
  14. using pointer_type = T*;
  15. using reference_type = T&;
  16. using const_pointer_type = const T*;
  17. using const_reference_type = const T&;
  18. pointer_type allocate(size_t sz)
  19. {
  20. return reinterpret_cast <pointer_type> (gp_config::memory_module::memory_allocator<gp_config::memory_module::memory_mode>(sizeof(T) * sz));
  21. }
  22. void deallocate(pointer_type ptr)
  23. {
  24. gp_config::memory_module::memory_deallocator<gp_config::memory_module::memory_mode>(ptr);
  25. }
  26. template<typename ...params>
  27. pointer_type construct(pointer_type ptr, params... args)
  28. {
  29. new(ptr) T(args...);
  30. return ptr;
  31. }
  32. void destroy(pointer_type v)
  33. {
  34. v->~T();
  35. }
  36. };
  37. }
  38. void* operator new(size_t sz)
  39. {
  40. auto ptr = gp_config::memory_module::memory_allocator<gp_config::memory_module::memory_mode>(sz);
  41. if constexpr (gp_config::has_exceptions)
  42. {
  43. if(!ptr)
  44. {
  45. throw gp::bad_alloc{};
  46. }
  47. }
  48. return ptr;
  49. }
  50. void operator delete (void* ptr) noexcept
  51. {
  52. gp_config::memory_module::memory_deallocator<gp_config::memory_module::memory_mode>(ptr);
  53. }
  54. */