8 #ifndef WPIUTIL_WPI_UV_BUFFER_H_
9 #define WPIUTIL_WPI_UV_BUFFER_H_
14 #include <initializer_list>
17 #include "wpi/ArrayRef.h"
18 #include "wpi/SmallVector.h"
19 #include "wpi/StringRef.h"
40 :
Buffer{
reinterpret_cast<const char*
>(arr.data()), arr.
size()} {}
41 Buffer(
char* base_,
size_t len_) {
45 Buffer(
const char* base_,
size_t len_) {
46 base =
const_cast<char*
>(base_);
60 std::memcpy(buf.base, in.
data(), in.
size());
66 std::memcpy(buf.base, in.begin(), in.
size());
96 template <
size_t DEPTH = 4>
109 if (m_pool.empty())
return Buffer::Allocate(m_size);
110 auto buf = m_pool.back();
127 for (
auto& buf : bufs) m_pool.emplace_back(buf.Move());
134 for (
auto& buf : m_pool) buf.Deallocate();
152 #endif // WPIUTIL_WPI_UV_BUFFER_H_
SimpleBufferPool(size_t size=4096)
Constructor.
Definition: Buffer.h:103
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:868
Buffer Allocate()
Allocate a buffer.
Definition: Buffer.h:108
Buffer operator()()
Allocate a buffer.
Definition: Buffer.h:119
void Clear()
Clear the pool, releasing all buffers.
Definition: Buffer.h:133
size_t Remaining() const
Get number of buffers left in the pool before a new buffer will be allocated from the heap...
Definition: Buffer.h:142
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const noexcept
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
namespace to hold default to_json function
Definition: SmallString.h:21
It should be possible to cast uv_buf_t[] to WSABUF[] see http://msdn.microsoft.com/en-us/library/ms74...
Definition: win.h:213
void Release(MutableArrayRef< Buffer > bufs)
Release allocated buffers back into the pool.
Definition: Buffer.h:126
A simple pool allocator for Buffers.
Definition: Buffer.h:97
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:999
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const noexcept
size - Get the string size.
Definition: StringRef.h:138
Data buffer.
Definition: Buffer.h:27
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:291