| Home | Libraries | People | FAQ | More

## Class buffer

boost::compute::buffer — A memory buffer on a compute device.

## Synopsis

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

    class buffer : public boost::compute::memory_object {
    public:

      // public member functions
      buffer();
      explicit buffer(cl_mem, bool = true);
      buffer(const context &, size_t, cl_mem_flags = read_write, void * = 0);
      buffer(const buffer &);
      buffer & operator=(const buffer &);
      buffer(buffer &&) noexcept;
      buffer & operator=(buffer &&) noexcept;
      ~buffer();
      size_t size() const;
      template<typename T> T get_info(cl_mem_info) const;
      template<int Enum> unspecified get_info() const;
      buffer clone(command_queue &) const;
      buffer create_subbuffer(cl_mem_flags, size_t, size_t);
    };

## Description

The buffer class represents a memory buffer on a compute device.

Buffers are allocated within a compute context. For example, to allocate a memory buffer for 32 float's:

Once created, data can be copied to and from the buffer using the `enqueue_*_buffer`() methods in the command_queue class. For example, to copy a set of `int` values from the host to the device:

    int data[] = { 1, 2, 3, 4 };

    queue.enqueue_write_buffer(buf, 0, 4 * sizeof(int), data);

Also see the copy() algorithm for a higher-level interface to copying data between the host and the device. For a higher-level, dynamically-resizable, type-safe container for data on a compute device, use the vector<T> class.

Buffer objects have reference semantics. Creating a copy of a buffer object simply creates another reference to the underlying OpenCL memory object. To create an actual copy use the buffer::clone() method.

See Also: context, command_queue

### `buffer` public member functions

1.     buffer();

   Creates a null buffer object.

2.     explicit buffer(cl_mem mem, bool retain = true);

   Creates a buffer object for `mem`. If `retain` is `true`, the reference count for `mem` will be incremented.

3.     buffer(const context & context, size_t size, cl_mem_flags flags = read_write,
              void * host_ptr = 0);

   Create a new memory buffer in of `size` with `flags` in `context`.

   See the documentation for

4.     buffer(const buffer & other);

   Creates a new buffer object as a copy of `other`.

5.     buffer & operator=(const buffer & other);

   Copies the buffer object from `other` to `*this`.

6.     buffer(buffer && other) noexcept;

   Move-constructs a new buffer object from `other`.

7.     buffer & operator=(buffer && other) noexcept;

   Move-assigns the buffer from `other` to `*this`.

8.     ~buffer();

   Destroys the buffer object.

9.     size_t size() const;

   Returns the size of the buffer in bytes.

10.     template<typename T> T get_info(cl_mem_info info) const;

    Returns information about the buffer.

    See the documentation for

11.     template<int Enum> unspecified get_info() const;

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

12.     buffer clone(command_queue & queue) const;

    Creates a new buffer with a copy of the data in `*this`. Uses `queue` to perform the copy.

13.     buffer create_subbuffer(cl_mem_flags flags, size_t origin, size_t size);

    Creates a new buffer out of this buffer. The new buffer is a sub region of this buffer. `flags` The mem_flags which should be used to create the new buffer `origin` The start index in this buffer `size` The size of the new sub buffer

    See the documentation for