Allocator.h 870 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. typedef void* (*allocate_func)(size_t size);
  5. typedef void (*free_func)(void* memory);
  6. #if defined(__cplusplus)
  7. extern "C"
  8. {
  9. #endif
  10. void register_allocator(allocate_func allocator, free_func release);
  11. void free_memory(void* memory);
  12. #if defined(__cplusplus)
  13. }
  14. #endif
  15. #if defined(__cplusplus)
  16. #include <string>
  17. #include <vector>
  18. class Allocator
  19. {
  20. public:
  21. static void* Allocate(size_t size);
  22. static void Free(void* memory);
  23. static char* CopyToAllocatedStringBuffer(const std::string& input);
  24. static char* CopyToAllocatedStringBuffer(const char* input);
  25. static void CopyStringVectorToNullTerminatedArray(const std::vector<std::string>& input, void*** output);
  26. static void CopyDataVectorToNullTerminatedArray(const std::vector<void*>& input, void*** output, int32_t elementSize);
  27. };
  28. #endif