static_structures.jl 854 B

123456789101112131415161718192021222324252627282930313233343536
  1. const jlstarpu_allocated_structures = Vector{Ptr{Void}}([])
  2. """
  3. Copies x_c to a new allocated memory zone.
  4. Returns the pointer toward the copied object. Every pointer
  5. returned by this function will be freed after a call to
  6. jlstarpu_free_allocated_structures
  7. """
  8. function jlstarpu_allocate_and_store(x_c :: T) where {T}
  9. allocated_ptr = Ptr{T}(Libc.malloc(sizeof(T)))
  10. if (allocated_ptr == C_NULL)
  11. error("Base.Libc.malloc returned NULL")
  12. end
  13. unsafe_store!(allocated_ptr, x_c)
  14. push!(jlstarpu_allocated_structures, Ptr{Void}(allocated_ptr))
  15. return allocated_ptr
  16. end
  17. """
  18. Frees every pointer allocated by jlstarpu_allocate_and_store
  19. """
  20. function jlstarpu_free_allocated_structures()
  21. map(Libc.free, jlstarpu_allocated_structures)
  22. empty!(jlstarpu_allocated_structures)
  23. return nothing
  24. end