Summary:
[Folly] `allocate_sys_buffer`.
For when a `malloc`'d buffer is required, with an associated deleter that calls `free`.
Reviewed By: JonCoens
Differential Revision:
D3590516
fbshipit-source-id:
644f4b5d5e8f19dbc8f29efe3e93517fba0ad72f
return std::shared_ptr<T>(std::move(ptr));
}
+using SysBufferDeleter = static_function_deleter<void, ::free>;
+using SysBufferUniquePtr = std::unique_ptr<void, SysBufferDeleter>;
+inline SysBufferUniquePtr allocate_sys_buffer(size_t size) {
+ return SysBufferUniquePtr(::malloc(size));
+}
+
/**
* A SimpleAllocator must provide two methods:
*
make_unique<string>("hello, world");
}
+TEST(allocate_sys_buffer, compiles) {
+ auto buf = allocate_sys_buffer(256);
+ // Freed at the end of the scope.
+}
+
template <std::size_t> struct T {};
template <std::size_t> struct S {};
template <std::size_t> struct P {};