alloc: eliminate 'raw' allocator distinction
This commit is contained in:
parent
6308166179
commit
4e25f6e3e2
@ -193,26 +193,26 @@ list (
|
||||
algo/sort.cpp
|
||||
algo/sort.hpp
|
||||
alloc/fwd.hpp
|
||||
alloc/affix.cpp
|
||||
alloc/affix.hpp
|
||||
alloc/aligned/direct.hpp
|
||||
alloc/aligned/foreign.hpp
|
||||
alloc/allocator.cpp
|
||||
alloc/allocator.hpp
|
||||
alloc/easy.hpp
|
||||
alloc/raw/traits.hpp
|
||||
alloc/raw/affix.cpp
|
||||
alloc/raw/affix.hpp
|
||||
alloc/raw/aligned/direct.hpp
|
||||
alloc/raw/aligned/foreign.hpp
|
||||
alloc/raw/fallback.cpp
|
||||
alloc/raw/fallback.hpp
|
||||
alloc/raw/linear.cpp
|
||||
alloc/raw/linear.hpp
|
||||
alloc/raw/malloc.cpp
|
||||
alloc/raw/malloc.hpp
|
||||
alloc/raw/null.cpp
|
||||
alloc/raw/null.hpp
|
||||
alloc/raw/stack.cpp
|
||||
alloc/raw/stack.hpp
|
||||
alloc/fallback.cpp
|
||||
alloc/fallback.hpp
|
||||
alloc/linear.cpp
|
||||
alloc/linear.hpp
|
||||
alloc/malloc.cpp
|
||||
alloc/malloc.hpp
|
||||
alloc/null.cpp
|
||||
alloc/null.hpp
|
||||
alloc/stack.cpp
|
||||
alloc/stack.hpp
|
||||
alloc/std.hpp
|
||||
alloc/traits.hpp
|
||||
alloc/traits.hpp
|
||||
annotation.hpp
|
||||
array/darray.hpp
|
||||
array/sarray.cpp
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
#include "affix.hpp"
|
||||
|
||||
using cruft::alloc::raw::affix;
|
||||
using cruft::alloc::affix;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -6,14 +6,13 @@
|
||||
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_ALLOC_RAW_AFFIX_HPP
|
||||
#define CRUFT_UTIL_ALLOC_RAW_AFFIX_HPP
|
||||
#pragma once
|
||||
|
||||
#include "../../view.hpp"
|
||||
#include "../view.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace cruft::alloc::raw {
|
||||
namespace cruft::alloc {
|
||||
/// a raw memory allocator which initialises an instance of PrefixT
|
||||
/// immediately before each allocation and, if specified, an instance
|
||||
/// of SuffixT after the allocation.
|
||||
@ -42,5 +41,3 @@ namespace cruft::alloc::raw {
|
||||
size_t offset (const void*) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -8,14 +8,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../../std.hpp"
|
||||
#include "../../../debug.hpp"
|
||||
#include "../../../view.hpp"
|
||||
#include "../../std.hpp"
|
||||
#include "../../debug.hpp"
|
||||
#include "../../view.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace cruft::alloc::raw::aligned {
|
||||
namespace cruft::alloc::aligned {
|
||||
/// wraps a child allocator and enforces a fixed alignment
|
||||
template <typename ChildT>
|
||||
class direct {
|
@ -10,14 +10,14 @@
|
||||
|
||||
#include "direct.hpp"
|
||||
|
||||
#include "../../../cast.hpp"
|
||||
#include "../../../pointer.hpp"
|
||||
#include "../../../debug.hpp"
|
||||
#include "../../cast.hpp"
|
||||
#include "../../pointer.hpp"
|
||||
#include "../../debug.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace cruft::alloc::raw::aligned {
|
||||
namespace cruft::alloc::aligned {
|
||||
/// wraps a child allocator and enforces a fixed alignment that is
|
||||
/// independant of the alignment of the provided source buffer.
|
||||
///
|
@ -6,15 +6,14 @@
|
||||
* Copyright 2015-2017 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_ALLOC_RAW_FALLBACK_HPP
|
||||
#define CRUFT_UTIL_ALLOC_RAW_FALLBACK_HPP
|
||||
#pragma once
|
||||
|
||||
#include "../../view.hpp"
|
||||
#include "../view.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <tuple>
|
||||
|
||||
namespace cruft::alloc::raw {
|
||||
namespace cruft::alloc {
|
||||
/// A raw memory allocator that allocates memory series of child
|
||||
/// allocators, preferring earlier allocators.
|
||||
template <typename ...ChildT>
|
||||
@ -39,5 +38,3 @@ namespace cruft::alloc::raw {
|
||||
std::tuple<ChildT&...> m_children;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -8,12 +8,12 @@
|
||||
|
||||
#include "linear.hpp"
|
||||
|
||||
#include "../traits.hpp"
|
||||
#include "traits.hpp"
|
||||
|
||||
#include "../../pointer.hpp"
|
||||
#include "../../debug.hpp"
|
||||
#include "../pointer.hpp"
|
||||
#include "../debug.hpp"
|
||||
|
||||
using cruft::alloc::raw::linear;
|
||||
using cruft::alloc::linear;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -34,7 +34,7 @@ linear::linear (linear &&rhs)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
linear&
|
||||
linear::operator= (cruft::alloc::raw::linear &&rhs)
|
||||
linear::operator= (linear &&rhs)
|
||||
{
|
||||
m_begin = std::exchange (rhs.m_begin, nullptr);
|
||||
m_end = std::exchange (rhs.m_end, nullptr);
|
@ -8,16 +8,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../std.hpp"
|
||||
#include "../../view.hpp"
|
||||
#include "../../pointer.hpp"
|
||||
#include "../../memory/buffer/traits.hpp"
|
||||
#include "../std.hpp"
|
||||
#include "../view.hpp"
|
||||
#include "../pointer.hpp"
|
||||
#include "../memory/buffer/traits.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
namespace cruft::alloc::raw {
|
||||
namespace cruft::alloc {
|
||||
// allocate progressively across a buffer without concern for deallocation.
|
||||
// deallocation is a noop; the only way to free allocations is via reset.
|
||||
class linear {
|
@ -7,8 +7,3 @@
|
||||
*/
|
||||
|
||||
#include "malloc.hpp"
|
||||
|
||||
#include "../../debug.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
@ -6,10 +6,9 @@
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_ALLOC_RAW_MALLOC_HPP
|
||||
#define CRUFT_UTIL_ALLOC_RAW_MALLOC_HPP
|
||||
#pragma once
|
||||
|
||||
#include "../../view.hpp"
|
||||
#include "../view.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
@ -23,7 +22,7 @@ posix_memalign (void **ptr, std::size_t align, std::size_t size)
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace cruft::alloc::raw {
|
||||
namespace cruft::alloc {
|
||||
class malloc {
|
||||
public:
|
||||
template <typename T>
|
||||
@ -55,6 +54,3 @@ namespace cruft::alloc::raw {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -9,11 +9,11 @@
|
||||
|
||||
#include "null.hpp"
|
||||
|
||||
#include "../../debug.hpp"
|
||||
#include "../debug.hpp"
|
||||
|
||||
#include <new>
|
||||
|
||||
using cruft::alloc::raw::null;
|
||||
using cruft::alloc::null;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -6,15 +6,14 @@
|
||||
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_ALLOC_RAW_NULL_HPP
|
||||
#define CRUFT_UTIL_ALLOC_RAW_NULL_HPP
|
||||
#pragma once
|
||||
|
||||
#include "../../view.hpp"
|
||||
#include "../view.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace cruft::alloc::raw {
|
||||
namespace cruft::alloc {
|
||||
// allocator that always fails, throwing bad_alloc. deallocate will
|
||||
// succeed with nullptr as with delete, but is undefined with other values
|
||||
// (it is likely to at least assert).
|
||||
@ -66,5 +65,3 @@ namespace cruft::alloc::raw {
|
||||
size_t remain (void) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_ALLOC_RAW_TRAITS_HPP
|
||||
#define CRUFT_UTIL_ALLOC_RAW_TRAITS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
namespace cruft::alloc::raw {
|
||||
template <typename AllocT, typename = std::void_t<>>
|
||||
struct has_aligned_allocate : std::false_type {};
|
||||
|
||||
template <typename AllocT>
|
||||
struct has_aligned_allocate<
|
||||
AllocT,
|
||||
std::void_t<
|
||||
decltype (
|
||||
std::declval<AllocT> ().allocate(16, 16)
|
||||
)
|
||||
>
|
||||
>: public std::true_type {};
|
||||
|
||||
|
||||
template <typename AllocT>
|
||||
constexpr auto has_aligned_allocate_v = has_aligned_allocate<AllocT>::value;
|
||||
};
|
||||
|
||||
#endif
|
@ -8,11 +8,11 @@
|
||||
|
||||
#include "stack.hpp"
|
||||
|
||||
#include "../../debug.hpp"
|
||||
#include "../../pointer.hpp"
|
||||
#include "../../cast.hpp"
|
||||
#include "../debug.hpp"
|
||||
#include "../pointer.hpp"
|
||||
#include "../cast.hpp"
|
||||
|
||||
using cruft::alloc::raw::stack;
|
||||
using cruft::alloc::stack;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -6,16 +6,15 @@
|
||||
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef CRUFT_UTIL_ALLOC_RAW_STACK_HPP
|
||||
#define CRUFT_UTIL_ALLOC_RAW_STACK_HPP
|
||||
#pragma once
|
||||
|
||||
#include "../../view.hpp"
|
||||
#include "../../pointer.hpp"
|
||||
#include "../view.hpp"
|
||||
#include "../pointer.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace cruft::alloc::raw {
|
||||
namespace cruft::alloc {
|
||||
// allocate memory from a buffer in a stacklike manner. deallocation that
|
||||
// is not correctly ordered has undefined (read 'bad') results.
|
||||
class stack {
|
||||
@ -112,5 +111,3 @@ namespace cruft::alloc::raw {
|
||||
std::byte *m_cursor;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -52,4 +52,27 @@ namespace cruft::alloc {
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename AllocatorT>
|
||||
constexpr auto is_allocator_v = is_allocator<AllocatorT>::value;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename AllocT, typename = std::void_t<>>
|
||||
struct has_aligned_allocate : std::false_type {};
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename AllocT>
|
||||
struct has_aligned_allocate<
|
||||
AllocT,
|
||||
std::void_t<
|
||||
decltype (
|
||||
std::declval<AllocT> ().allocate(16, 16)
|
||||
)
|
||||
>
|
||||
>: public std::true_type {};
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <typename AllocT>
|
||||
constexpr auto has_aligned_allocate_v = has_aligned_allocate<AllocT>::value;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "tap.hpp"
|
||||
|
||||
#include "alloc/raw/aligned/direct.hpp"
|
||||
#include "alloc/raw/linear.hpp"
|
||||
#include "alloc/aligned/direct.hpp"
|
||||
#include "alloc/linear.hpp"
|
||||
|
||||
|
||||
int
|
||||
@ -20,7 +20,7 @@ main (int, char**)
|
||||
// we're probably operating correctly.
|
||||
static constexpr std::size_t alignment = 3;
|
||||
|
||||
cruft::alloc::raw::aligned::direct<cruft::alloc::raw::linear> alloc (
|
||||
cruft::alloc::aligned::direct<cruft::alloc::linear> alloc (
|
||||
cruft::make_view (buffer), alignment
|
||||
);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "alloc/raw/aligned/foreign.hpp"
|
||||
#include "alloc/raw/linear.hpp"
|
||||
#include "alloc/aligned/foreign.hpp"
|
||||
#include "alloc/linear.hpp"
|
||||
#include "pointer.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
@ -17,7 +17,7 @@ main ()
|
||||
alignof (std::max_align_t)
|
||||
) + increment;
|
||||
|
||||
cruft::alloc::raw::aligned::foreign<cruft::alloc::raw::linear> alloc (
|
||||
cruft::alloc::aligned::foreign<cruft::alloc::linear> alloc (
|
||||
cruft::view(base,std::end(buffer)),
|
||||
alignment
|
||||
);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "alloc/easy.hpp"
|
||||
#include "alloc/raw/linear.hpp"
|
||||
#include "alloc/linear.hpp"
|
||||
#include "memory/buffer/simple.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
@ -28,7 +28,7 @@ int main ()
|
||||
cruft::memory::buffer::simple buf (elements);
|
||||
|
||||
cruft::alloc::easy::owned <
|
||||
cruft::alloc::raw::linear,
|
||||
cruft::alloc::linear,
|
||||
cruft::memory::buffer::simple
|
||||
> alloc (
|
||||
std::move (buf)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "tap.hpp"
|
||||
#include "alloc/raw/linear.hpp"
|
||||
#include "alloc/linear.hpp"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -11,7 +11,7 @@ main (void)
|
||||
constexpr size_t BUFFER_SIZE = 1024;
|
||||
|
||||
alignas (std::max_align_t) u08 memory[BUFFER_SIZE];
|
||||
cruft::alloc::raw::linear store (cruft::make_view (memory));
|
||||
cruft::alloc::linear store (cruft::make_view (memory));
|
||||
|
||||
tap.expect_eq (store.begin (), std::begin (memory), "base pointers match");
|
||||
tap.expect_eq (store.offset (std::begin (memory)), 0u, "base offset is 0");
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include "tap.hpp"
|
||||
#include "alloc/raw/stack.hpp"
|
||||
#include "alloc/stack.hpp"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
n_allocations (cruft::alloc::raw::stack &store,
|
||||
n_allocations (cruft::alloc::stack &store,
|
||||
unsigned count,
|
||||
size_t bytes,
|
||||
size_t alignment = alignof (std::max_align_t))
|
||||
@ -32,7 +32,7 @@ main (void)
|
||||
alignas (std::max_align_t) std::byte memory[BUFFER_SIZE];
|
||||
std::fill (std::begin (memory), std::end (memory), std::byte{0});
|
||||
|
||||
cruft::alloc::raw::stack store (cruft::make_view(memory, memory + BUFFER_AVAILABLE));
|
||||
cruft::alloc::stack store (cruft::make_view(memory, memory + BUFFER_AVAILABLE));
|
||||
|
||||
tap.expect_eq (store.begin (), std::begin (memory), "base pointers match");
|
||||
tap.expect_eq (store.offset (std::begin (memory)), 0u, "base offset is 0");
|
||||
|
Loading…
Reference in New Issue
Block a user