Commit e28213bf authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot 7

allocate_sys_buffer

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
parent df8ec793
......@@ -114,6 +114,12 @@ std::shared_ptr<T> to_shared_ptr(std::unique_ptr<T, D>&& ptr) {
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:
*
......
......@@ -33,6 +33,11 @@ TEST(make_unique, compatible_with_std_make_unique) {
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 {};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment