Class memory_object

| Home | Libraries | People | FAQ | More

## Class memory_object

boost::compute::memory_object — Base-class for memory objects.

## Synopsis

    // In header: <boost/compute/memory_object.hpp>

    class memory_object {
    public:

      // Flags for the creation of memory objects.
      enum mem_flags { read_write = = CL_MEM_READ_WRITE,
                       read_only = = CL_MEM_READ_ONLY,
                       write_only = = CL_MEM_WRITE_ONLY,
                       use_host_ptr = = CL_MEM_USE_HOST_PTR,
                       alloc_host_ptr = = CL_MEM_ALLOC_HOST_PTR,
                       copy_host_ptr = = CL_MEM_COPY_HOST_PTR };

      // Symbolic names for the OpenCL address spaces.
      enum address_space { global_memory, local_memory, private_memory,
                           constant_memory };

      // public member functions
      cl_mem & get() const;
      size_t get_memory_size() const;
      cl_mem_object_type get_memory_type() const;
      cl_mem_flags get_memory_flags() const;
      context get_context() const;
      void * get_host_ptr() const;
      uint_ reference_count() const;
      template<typename T> T get_memory_info(cl_mem_info) const;
      void set_destructor_callback(void(BOOST_COMPUTE_CL_CALLBACK *callback)(cl_mem memobj, void *user_data),
                                   void * = 0);
      template<typename Function> void set_destructor_callback(Function);
      bool operator==(const memory_object &) const;
      bool operator!=(const memory_object &) const;
    };

## Description

The memory_object class is the base-class for memory objects on compute devices.

See Also:

buffer, vector

### `memory_object` public member functions

1.     cl_mem & get() const;

   Returns the underlying OpenCL memory object.

2.     size_t get_memory_size() const;

   Returns the size of the memory object in bytes.

3.     cl_mem_object_type get_memory_type() const;

   Returns the type for the memory object.

4.     cl_mem_flags get_memory_flags() const;

   Returns the flags for the memory object.

5.     context get_context() const;

   Returns the context for the memory object.

6.     void * get_host_ptr() const;

   Returns the host pointer associated with the memory object.

7.     uint_ reference_count() const;

   Returns the reference count for the memory object.

8.     template<typename T> T get_memory_info(cl_mem_info info) const;

   Returns information about the memory object.

   See the documentation for clGetMemObjectInfo() for more information.

9.     void set_destructor_callback(void(BOOST_COMPUTE_CL_CALLBACK *callback)(cl_mem memobj, void *user_data),
                                    void * user_data = 0);

   Registers a function to be called when the memory object is deleted and its resources freed.

   See the documentation for clSetMemObjectDestructorCallback() for more information.

   | Warning
   This method is only available if the OpenCL version is 1.1 or later.

10.     template<typename Function> void set_destructor_callback(Function callback);

    Registers a function to be called when the memory object is deleted and its resources freed.

    The function specified by `callback` must be invokable with zero arguments (e.g. `callback()`).

    | Warning
    This method is only available if the OpenCL version is 1.1 or later.

11.     bool operator==(const memory_object & other) const;

    Returns `true` if the memory object is the same as `other`.

12.     bool operator!=(const memory_object & other) const;

    Returns `true` if the memory object is different from `other`.