memory.h 695 B

123456789101112131415161718192021222324252627282930
  1. // This code is in the public domain -- Ignacio Castaño <[email protected]>
  2. #ifndef NV_CORE_MEMORY_H
  3. #define NV_CORE_MEMORY_H
  4. #include "nvcore.h"
  5. #include <stdlib.h>
  6. namespace nv {
  7. // C++ helpers.
  8. template <typename T> inline T * malloc(size_t count) {
  9. return (T *)::malloc(sizeof(T) * count);
  10. }
  11. template <typename T> inline T * realloc(T * ptr, size_t count) {
  12. return (T *)::realloc(ptr, sizeof(T) * count);
  13. }
  14. template <typename T> inline void free(const T * ptr) {
  15. ::free((void *)ptr);
  16. }
  17. template <typename T> inline void zero(T & data) {
  18. memset(&data, 0, sizeof(T));
  19. }
  20. } // nv namespace
  21. #endif // NV_CORE_MEMORY_H