| Line | Branch | Exec | Source | 
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | namespace spice::compiler { | ||
| 6 | |||
| 7 | // Typedefs | ||
| 8 | using byte = uint8_t; | ||
| 9 | |||
| 10 | class MemoryManager { | ||
| 11 | protected: | ||
| 12 | ~MemoryManager() = default; | ||
| 13 | |||
| 14 | public: | ||
| 15 | [[nodiscard]] virtual byte *allocate(size_t size) const = 0; | ||
| 16 | virtual void deallocate(byte *ptr) const = 0; | ||
| 17 | }; | ||
| 18 | |||
| 19 | class DefaultMemoryManager final : public MemoryManager { | ||
| 20 | public: | ||
| 21 | 76750 | [[nodiscard]] byte *allocate(const size_t size) const override { return static_cast<byte *>(malloc(size)); } | |
| 22 | 76750 | void deallocate(byte *ptr) const override { free(ptr); } | |
| 23 | }; | ||
| 24 | |||
| 25 | } // namespace spice::compiler | ||
| 26 | |||
| 27 | // Overload new and delete operators for debugging purposes | ||
| 28 | #ifdef SPICE_NEW_DELETE_OVERLOADED | ||
| 29 | void *operator new(size_t n) noexcept(false) { return malloc(n); } | ||
| 30 | void operator delete(void *ptr) noexcept { free(ptr); } | ||
| 31 | #endif | ||
| 32 |