You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2021/01/12 23:50:35 UTC

[datasketches-cpp] branch tuple_allocator_fix created (now aff3549)

This is an automated email from the ASF dual-hosted git repository.

alsay pushed a change to branch tuple_allocator_fix
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git.


      at aff3549  fixed allocator handling

This branch includes the following new commits:

     new aff3549  fixed allocator handling

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org


[datasketches-cpp] 01/01: fixed allocator handling

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch tuple_allocator_fix
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git

commit aff3549ab80b429151260fe5dcefda4bf91fb50e
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jan 12 15:50:18 2021 -0800

    fixed allocator handling
---
 tuple/include/theta_update_sketch_base_impl.hpp |  2 +-
 tuple/include/tuple_sketch.hpp                  | 16 +++++++++-------
 tuple/include/tuple_sketch_impl.hpp             |  4 ++--
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/tuple/include/theta_update_sketch_base_impl.hpp b/tuple/include/theta_update_sketch_base_impl.hpp
index 8fdb3d8..bbf845b 100644
--- a/tuple/include/theta_update_sketch_base_impl.hpp
+++ b/tuple/include/theta_update_sketch_base_impl.hpp
@@ -69,7 +69,7 @@ entries_(nullptr)
 
 template<typename EN, typename EK, typename A>
 theta_update_sketch_base<EN, EK, A>::theta_update_sketch_base(theta_update_sketch_base&& other) noexcept:
-allocator_(other.allocator_),
+allocator_(std::move(other.allocator_)),
 is_empty_(other.is_empty_),
 lg_cur_size_(other.lg_cur_size_),
 lg_nom_size_(other.lg_nom_size_),
diff --git a/tuple/include/tuple_sketch.hpp b/tuple/include/tuple_sketch.hpp
index 2292937..1cbd243 100644
--- a/tuple/include/tuple_sketch.hpp
+++ b/tuple/include/tuple_sketch.hpp
@@ -444,19 +444,21 @@ protected:
   // for deserialize
   class deleter_of_summaries {
   public:
-    deleter_of_summaries(uint32_t num, bool destroy): num(num), destroy(destroy) {}
-    void set_destroy(bool destroy) { this->destroy = destroy; }
+    deleter_of_summaries(uint32_t num, bool destroy, const Allocator& allocator):
+      allocator_(allocator), num_(num), destroy_(destroy) {}
+    void set_destroy(bool destroy) { destroy_ = destroy; }
     void operator() (Summary* ptr) const {
       if (ptr != nullptr) {
-        if (destroy) {
-          for (uint32_t i = 0; i < num; ++i) ptr[i].~Summary();
+        if (destroy_) {
+          for (uint32_t i = 0; i < num_; ++i) ptr[i].~Summary();
         }
-        Allocator().deallocate(ptr, num);
+        allocator_.deallocate(ptr, num_);
       }
     }
   private:
-    uint32_t num;
-    bool destroy;
+    Allocator allocator_;
+    uint32_t num_;
+    bool destroy_;
   };
 
   virtual void print_specifics(std::basic_ostream<char>& os) const;
diff --git a/tuple/include/tuple_sketch_impl.hpp b/tuple/include/tuple_sketch_impl.hpp
index 63552d7..52e2ebf 100644
--- a/tuple/include/tuple_sketch_impl.hpp
+++ b/tuple/include/tuple_sketch_impl.hpp
@@ -470,7 +470,7 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(std::istream&
   std::vector<Entry, AllocEntry> entries(alloc);
   if (!is_empty) {
     entries.reserve(num_entries);
-    std::unique_ptr<S, deleter_of_summaries> summary(alloc.allocate(1), deleter_of_summaries(1, false));
+    std::unique_ptr<S, deleter_of_summaries> summary(alloc.allocate(1), deleter_of_summaries(1, false, allocator));
     for (size_t i = 0; i < num_entries; ++i) {
       uint64_t key;
       is.read(reinterpret_cast<char*>(&key), sizeof(uint64_t));
@@ -533,7 +533,7 @@ compact_tuple_sketch<S, A> compact_tuple_sketch<S, A>::deserialize(const void* b
   std::vector<Entry, AllocEntry> entries(alloc);
   if (!is_empty) {
     entries.reserve(num_entries);
-    std::unique_ptr<S, deleter_of_summaries> summary(alloc.allocate(1), deleter_of_summaries(1, false));
+    std::unique_ptr<S, deleter_of_summaries> summary(alloc.allocate(1), deleter_of_summaries(1, false, allocator));
     for (size_t i = 0; i < num_entries; ++i) {
       uint64_t key;
       ptr += copy_from_mem(ptr, &key, sizeof(key));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org