1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP
12 #define BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP
14 #include <boost/compute/buffer.hpp>
15 #include <boost/compute/system.hpp>
16 #include <boost/compute/context.hpp>
17 #include <boost/compute/detail/device_ptr.hpp>
21 namespace experimental {
23 // bring device_ptr into the experimental namespace
24 using detail::device_ptr;
28 malloc(std::size_t size, const context &context = system::default_context())
30 buffer buf(context, size * sizeof(T));
31 clRetainMemObject(buf.get());
32 return device_ptr<T>(buf);
35 inline device_ptr<char>
36 malloc(std::size_t size, const context &context = system::default_context())
38 return malloc<char>(size, context);
42 inline void free(device_ptr<T> &ptr)
44 clReleaseMemObject(ptr.get_buffer().get());
47 } // end experimental namespace
48 } // end compute namespace
49 } // end boost namespace
51 #endif // BOOST_COMPUTE_EXPERIMENTAL_MALLOC_HPP