Program Listing for File memory.h

Return to documentation for file (thrust/memory.h)

/*
 *  Copyright 2008-2013 NVIDIA Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include <thrust/detail/config.h>

#include <thrust/detail/type_traits/pointer_traits.h>
#include <thrust/detail/pointer.h>
#include <thrust/detail/reference.h>
#include <thrust/detail/raw_pointer_cast.h>
#include <thrust/detail/raw_reference_cast.h>
#include <thrust/detail/malloc_and_free.h>
#include <thrust/detail/temporary_buffer.h>

namespace thrust
{


// define pointer for the purpose of Doxygenating it
// it is actually defined elsewhere
#if 0
template<typename Element, typename Tag, typename Reference = thrust::use_default, typename Derived = thrust::use_default>
  class pointer
{
  public:
    typedef typename super_t::base_type raw_pointer;

    __host__ __device__
    pointer();

    template<typename OtherElement>
    __host__ __device__
    explicit pointer(OtherElement *ptr);

    template<typename OtherPointer>
    __host__ __device__
    pointer(const OtherPointer &other,
            typename thrust::detail::enable_if_pointer_is_convertible<
              OtherPointer,
              pointer<Element,Tag,Reference,Derived>
            >::type * = 0);

    template<typename OtherPointer>
    __host__ __device__
    typename thrust::detail::enable_if_pointer_is_convertible<
      OtherPointer,
      pointer,
      derived_type &
    >::type
    operator=(const OtherPointer &other);

    __host__ __device__
    Element *get() const;
};
#endif

// define pointer for the purpose of Doxygenating it
// it is actually defined elsewhere
#if 0
template<typename Element, typename Pointer, typename Derived = thrust::use_default>
  class reference
{
  public:
    typedef Pointer                                              pointer;

    typedef typename thrust::detail::remove_const<Element>::type value_type;

    __host__ __device__
    explicit reference(const pointer &ptr);

    template<typename OtherElement, typename OtherPointer, typename OtherDerived>
    __host__ __device__
    reference(const reference<OtherElement,OtherPointer,OtherDerived> &other,
              typename thrust::detail::enable_if_convertible<
                typename reference<OtherElement,OtherPointer,OtherDerived>::pointer,
                pointer
              >::type * = 0);

    __host__ __device__
    derived_type &operator=(const reference &other);

    template<typename OtherElement, typename OtherPointer, typename OtherDerived>
    __host__ __device__
    derived_type &operator=(const reference<OtherElement,OtherPointer,OtherDerived> &other);

    __host__ __device__
    derived_type &operator=(const value_type &x);

    __host__ __device__
    pointer operator&() const;

    __host__ __device__
    operator value_type () const;

    __host__ __device__
    void swap(derived_type &other);

    derived_type &operator++();
};
#endif

template<typename DerivedPolicy>
__host__ __device__
pointer<void,DerivedPolicy> malloc(const thrust::detail::execution_policy_base<DerivedPolicy> &system, std::size_t n);


template<typename T, typename DerivedPolicy>
__host__ __device__
pointer<T,DerivedPolicy> malloc(const thrust::detail::execution_policy_base<DerivedPolicy> &system, std::size_t n);


template<typename T, typename DerivedPolicy>
__host__ __device__
thrust::pair<thrust::pointer<T,DerivedPolicy>, typename thrust::pointer<T,DerivedPolicy>::difference_type>
get_temporary_buffer(const thrust::detail::execution_policy_base<DerivedPolicy> &system, typename thrust::pointer<T,DerivedPolicy>::difference_type n);


template<typename DerivedPolicy, typename Pointer>
__host__ __device__
void free(const thrust::detail::execution_policy_base<DerivedPolicy> &system, Pointer ptr);


template<typename DerivedPolicy, typename Pointer>
__host__ __device__
void return_temporary_buffer(const thrust::detail::execution_policy_base<DerivedPolicy> &system, Pointer p);


template<typename Pointer>
__host__ __device__
inline typename thrust::detail::pointer_traits<Pointer>::raw_pointer
  raw_pointer_cast(const Pointer &ptr);


template<typename T>
__host__ __device__
inline typename detail::raw_reference<T>::type
  raw_reference_cast(T &ref);


template<typename T>
__host__ __device__
inline typename detail::raw_reference<const T>::type
  raw_reference_cast(const T &ref);


} // end thrust