diff --git a/.travis.yml b/.travis.yml index 9955fb8c..d2a22c56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,5 @@ script: - mkdir $CXX && cd $CXX - ../cmake-3.3.1-Linux-x86_64/bin/cmake -DCMAKE_BUILD_TYPE=$build_type -DCMAKE_CXX_FLAGS="-Wall -Wextra -pedantic -Wno-parentheses" ../ - ../cmake-3.3.1-Linux-x86_64/bin/cmake --build . - - ./test/foonathan_memory_test \ No newline at end of file + - ./test/foonathan_memory_test + - ./test/foonathan_memory_profiling 1 \ No newline at end of file diff --git a/README.md b/README.md index e3b391f1..107a53e5 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ In addition: ## Basic example ```cpp -include +#include #include #include diff --git a/doc/index.md b/doc/index.md index 8ce72087..8cf36980 100644 --- a/doc/index.md +++ b/doc/index.md @@ -38,7 +38,7 @@ The concepts of this library are defined are [here](md_doc_concepts.html). ## Basic example ```cpp - include + #include #include #include diff --git a/src/detail/free_list.cpp b/src/detail/free_list.cpp index 8b19c03b..e5a73cf1 100644 --- a/src/detail/free_list.cpp +++ b/src/detail/free_list.cpp @@ -479,7 +479,8 @@ void* ordered_free_memory_list::allocate(std::size_t n) FOONATHAN_NOEXCEPT xor_list_change(i.next, i.last, i.prev); // change prev pointer from i.next to i.prev capacity_ -= i.size(actual_size); - if (less(i.prev, last_dealloc_) && less(last_dealloc_, i.next)) + // if last_dealloc_ points into the array being removed + if (less_equal(i.first, last_dealloc_) && less_equal(last_dealloc_, i.last)) { // move last_dealloc just outside range last_dealloc_ = i.next; diff --git a/src/detail/free_list_utils.hpp b/src/detail/free_list_utils.hpp index b094a813..c04be145 100644 --- a/src/detail/free_list_utils.hpp +++ b/src/detail/free_list_utils.hpp @@ -122,6 +122,11 @@ namespace foonathan { namespace memory #endif } + inline bool less_equal(void *a, void *b) FOONATHAN_NOEXCEPT + { + return a == b || less(a, b); + } + inline bool greater(void *a, void *b) FOONATHAN_NOEXCEPT { #if FOONATHAN_HOSTED_IMPLEMENTATION @@ -130,6 +135,11 @@ namespace foonathan { namespace memory return to_int(a) < to_int(b); #endif } + + inline bool greater_equal(void *a, void *b) FOONATHAN_NOEXCEPT + { + return a == b || greater(a, b); + } } // namespace detail }} // namespace foonathan::memory diff --git a/src/detail/small_free_list.cpp b/src/detail/small_free_list.cpp index 6a3e457b..c81e2683 100644 --- a/src/detail/small_free_list.cpp +++ b/src/detail/small_free_list.cpp @@ -344,8 +344,10 @@ chunk* small_free_memory_list::find_chunk_impl(std::size_t n) FOONATHAN_NOEXCEPT return c; cur_forward = cur_forward->next; - cur_backward = cur_backward->next; - } while (cur_forward != cur_backward); + cur_backward = cur_backward->prev; + FOONATHAN_MEMORY_ASSERT(cur_forward != alloc_chunk_); + FOONATHAN_MEMORY_ASSERT(cur_backward != alloc_chunk_); + } while (true); FOONATHAN_MEMORY_UNREACHABLE("there is memory available somewhere..."); return nullptr; } diff --git a/test/benchmark.hpp b/test/benchmark.hpp index cc10c566..d9bda50f 100644 --- a/test/benchmark.hpp +++ b/test/benchmark.hpp @@ -26,7 +26,7 @@ std::size_t measure(F func, Args&&... args) return std::size_t(duration.count()); } -const std::size_t sample_size = 1024u; +std::size_t sample_size = 1024u; template std::size_t benchmark(F measure_func, Alloc make_alloc, Args&& ... args) diff --git a/test/profiling.cpp b/test/profiling.cpp index d06fbafc..43b66aae 100644 --- a/test/profiling.cpp +++ b/test/profiling.cpp @@ -114,8 +114,11 @@ void benchmark_array(std::initializer_list counts, benchmark_array(counts, node_sizes, array_sizes); } -int main() +int main(int argc, char *argv[]) { + if (argc >= 2) + sample_size = std::size_t(std::atoi(argv[1])); + class comma_numpunct : public std::numpunct { protected: