From 851d0de995d2a3089a2f05a56807aa889ebbbeba Mon Sep 17 00:00:00 2001 From: Splendour Date: Fri, 8 Feb 2019 21:19:31 +0200 Subject: [PATCH 1/4] Use supplied memory allocator for priority_queue --- crnlib/allocator.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 crnlib/allocator.h diff --git a/crnlib/allocator.h b/crnlib/allocator.h new file mode 100644 index 00000000..19e29a12 --- /dev/null +++ b/crnlib/allocator.h @@ -0,0 +1,36 @@ +#pragma once +#include "crn_mem.h" + +namespace crnlib +{ + template + class allocator + { + public: + using value_type = T; + template allocator(allocator const&) noexcept {} + allocator() noexcept {}; + + value_type* allocate(std::size_t n) + { + return static_cast(crnlib_malloc(n)); + } + + void deallocate(value_type* p, std::size_t) noexcept + { + crnlib_free(p); + } + }; + + template + bool operator==(allocator const&, allocator const&) noexcept + { + return true; + } + + template + bool operator!=(allocator const& x, allocator const& y) noexcept + { + return !(x == y); + } +} \ No newline at end of file From 3d90648ed33d34220b4c774d80f0a0a22750d632 Mon Sep 17 00:00:00 2001 From: Splendour Date: Fri, 8 Feb 2019 21:20:29 +0200 Subject: [PATCH 2/4] no std allocator missing files --- crnlib/crn_dxt_hc.cpp | 6 +++--- crnlib/crn_tree_clusterizer.h | 10 ++++++---- crnlib/crnlib.2010.vcxproj | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crnlib/crn_dxt_hc.cpp b/crnlib/crn_dxt_hc.cpp index a099be88..825f0c0b 100644 --- a/crnlib/crn_dxt_hc.cpp +++ b/crnlib/crn_dxt_hc.cpp @@ -716,7 +716,7 @@ void dxt_hc::determine_color_endpoints() { m_pTask_pool->queue_task(&Node::sort_task, i, &nodes[i]); m_pTask_pool->join(); - std::priority_queue queue; + std::priority_queue>> queue; for (uint i = 0; i < nodes.size(); i++) queue.push(nodes[i]); @@ -1055,7 +1055,7 @@ void dxt_hc::create_color_selector_codebook() { m_pTask_pool->queue_task(&SelectorNode::sort_task, i, &nodes[i]); m_pTask_pool->join(); - std::priority_queue queue; + std::priority_queue>> queue; for (uint i = 0; i < nodes.size(); i++) queue.push(nodes[i]); @@ -1213,7 +1213,7 @@ void dxt_hc::create_alpha_selector_codebook() { m_pTask_pool->queue_task(&SelectorNode::sort_task, i, &nodes[i]); m_pTask_pool->join(); - std::priority_queue queue; + std::priority_queue>> queue; for (uint i = 0; i < nodes.size(); i++) queue.push(nodes[i]); diff --git a/crnlib/crn_tree_clusterizer.h b/crnlib/crn_tree_clusterizer.h index d6785c3b..1c0a342e 100644 --- a/crnlib/crn_tree_clusterizer.h +++ b/crnlib/crn_tree_clusterizer.h @@ -4,6 +4,7 @@ #include "crn_matrix.h" #include "crn_threading.h" #include +#include "allocator.h" namespace crnlib { template @@ -33,7 +34,7 @@ class tree_clusterizer { void split_alternative_node_task(uint64, void* pData_ptr) { split_alternative_node_task_params* pParams = (split_alternative_node_task_params*)pData_ptr; - std::priority_queue node_queue; + std::priority_queue>> node_queue; uint begin_node = pParams->alternative_node, end_node = begin_node, splits = 0; m_nodes[end_node] = m_nodes[pParams->main_node]; @@ -78,7 +79,7 @@ class tree_clusterizer { root.m_variance = (float)(ttsum - (root.m_centroid.dot(root.m_centroid) / root.m_total_weight)); root.m_centroid *= (1.0f / root.m_total_weight); - std::priority_queue node_queue; + std::priority_queue>> node_queue; uint begin_node = 0, end_node = begin_node, splits = 0; m_nodes[end_node] = root; node_queue.push(NodeInfo(end_node, root.m_variance)); @@ -89,7 +90,7 @@ class tree_clusterizer { while (splits < max_splits && node_queue.size() != num_tasks && split_node(node_queue, end_node, pTask_pool)) splits++; if (node_queue.size() == num_tasks) { - std::priority_queue alternative_node_queue = node_queue; + std::priority_queue>> alternative_node_queue = node_queue; uint alternative_node = max_splits << 1, alternative_max_splits = max_splits / num_tasks; crnlib::vector params(num_tasks); for (uint task = 0; !alternative_node_queue.empty(); alternative_node_queue.pop(), alternative_node += alternative_max_splits << 1, task++) { @@ -193,7 +194,8 @@ class tree_clusterizer { } } - bool split_node(std::priority_queue& node_queue, uint& end_node, task_pool* pTask_pool = 0) { + bool split_node(std::priority_queue>>& node_queue, + uint& end_node, task_pool* pTask_pool = 0) { if (node_queue.empty()) return false; diff --git a/crnlib/crnlib.2010.vcxproj b/crnlib/crnlib.2010.vcxproj index ec5d528f..59021301 100644 --- a/crnlib/crnlib.2010.vcxproj +++ b/crnlib/crnlib.2010.vcxproj @@ -550,6 +550,7 @@ + From d1f101fd475a1ed000a17f470bd6ac81cf5b2fea Mon Sep 17 00:00:00 2001 From: Splendour Date: Fri, 8 Feb 2019 22:06:46 +0200 Subject: [PATCH 3/4] allocator fix --- crnlib/allocator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crnlib/allocator.h b/crnlib/allocator.h index 19e29a12..1ceb58d3 100644 --- a/crnlib/allocator.h +++ b/crnlib/allocator.h @@ -13,12 +13,12 @@ namespace crnlib value_type* allocate(std::size_t n) { - return static_cast(crnlib_malloc(n)); + return static_cast(crnlib_malloc(n * sizeof(T))); } void deallocate(value_type* p, std::size_t) noexcept { - crnlib_free(p); + crnlib_delete(p); } }; From 507ae7ad74ae1bd8563f3030cd9a421574037bf1 Mon Sep 17 00:00:00 2001 From: Splendour Date: Fri, 8 Feb 2019 22:08:32 +0200 Subject: [PATCH 4/4] delete -> free --- crnlib/allocator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crnlib/allocator.h b/crnlib/allocator.h index 1ceb58d3..29eaadaa 100644 --- a/crnlib/allocator.h +++ b/crnlib/allocator.h @@ -18,7 +18,7 @@ namespace crnlib void deallocate(value_type* p, std::size_t) noexcept { - crnlib_delete(p); + crnlib_free(p); } };