diff --git a/reconstruct/ast.py b/reconstruct/ast.py index a0dbe7b..a260ccb 100644 --- a/reconstruct/ast.py +++ b/reconstruct/ast.py @@ -683,6 +683,8 @@ class groupby_c(ast_node): else: gscanner.add(f'{ce[0]}.emplace_back({get_var_names_ex(ex)});\n') + gscanner.add(f'GC::scratch_space->release();') + gscanner.finalize() self.context.emitc(f'GC::scratch_space = nullptr;') diff --git a/server/gc.h b/server/gc.h index 0ba5f1d..d8e84f8 100644 --- a/server/gc.h +++ b/server/gc.h @@ -82,7 +82,7 @@ public: start_deamon(); GC::gc_handle = this; - this->scratch.init(scratch_sz); + this->scratch.init(1); } // 256 MB ~GC(){ diff --git a/server/libaquery.cpp b/server/libaquery.cpp index b59f658..60e4b81 100644 --- a/server/libaquery.cpp +++ b/server/libaquery.cpp @@ -480,8 +480,8 @@ void ScratchSpace::init(size_t initial_capacity) { } inline void* ScratchSpace::alloc(uint32_t sz){ - this->cnt += sz; // major cost ptr = this->cnt; + this->cnt += sz; // major cost if (this->cnt > capacity) { [[unlikely]] capacity = this->cnt + (capacity >> 1); @@ -499,14 +499,13 @@ inline void ScratchSpace::register_ret(void* ret){ inline void ScratchSpace::release(){ ptr = cnt = 0; - ret = nullptr; auto vec_tmpmem_fractions = static_cast*>(temp_memory_fractions); if (vec_tmpmem_fractions->size) { - //[[unlikely]] + [[unlikely]] for(auto& mem : *vec_tmpmem_fractions){ - free(mem); - //GC::gc_handle->reg(mem); + //free(mem); + GC::gc_handle->reg(mem); } vec_tmpmem_fractions->clear(); } @@ -514,6 +513,7 @@ inline void ScratchSpace::release(){ inline void ScratchSpace::reset() { this->release(); + ret = nullptr; if (capacity != initial_capacity){ capacity = initial_capacity; scratchspace = static_cast(realloc(scratchspace, capacity)); diff --git a/server/monetdb_conn.cpp b/server/monetdb_conn.cpp index c577c8b..533a6f0 100644 --- a/server/monetdb_conn.cpp +++ b/server/monetdb_conn.cpp @@ -75,11 +75,11 @@ void Server::connect(Context *cxt){ printf("Error: Server %p already connected. Restart? (Y/n). \n", server); char c[50]; std::cin.getline(c, 49); - for(int i = 0; i < 50; ++i){ + for(int i = 0; i < 50; ++i) { if (!c[i] || c[i] == 'y' || c[i] == 'Y'){ monetdbe_close(*server); free(*server); - this->server = 0; + this->server = nullptr; break; } else if(c[i]&&!(c[i] == ' ' || c[i] == '\t')) @@ -153,8 +153,7 @@ void Server::print_results(const char* sep, const char* end){ szs [i] = monetdbe_type_szs[cols[i]->type]; header_string = header_string + cols[i]->name + sep + '|' + sep; } - const size_t l_sep = strlen(sep) + 1; - if (header_string.size() - l_sep >= 0) + if (const size_t l_sep = strlen(sep) + 1; header_string.size() >= l_sep) header_string.resize(header_string.size() - l_sep); header_string += end + std::string(header_string.size(), '=') + end; fputs(header_string.c_str(), stdout); diff --git a/server/table.h b/server/table.h index 36f7230..6f7dfdf 100644 --- a/server/table.h +++ b/server/table.h @@ -332,7 +332,7 @@ template struct TableInfo; template struct TableView; template -constexpr inline auto& get(const TableInfo<_Types...>& table) noexcept { +constexpr auto& get(const TableInfo<_Types...>& table) noexcept { if constexpr (order) return *(ColRef>> *) & (table.colrefs[_Index]); else @@ -340,7 +340,7 @@ constexpr inline auto& get(const TableInfo<_Types...>& table) noexcept { } template -constexpr inline ColRef>>& get(const TableView<_Types...>& table) noexcept { +constexpr ColRef>>& get(const TableView<_Types...>& table) noexcept { return *(ColRef>> *) & (table.info.colrefs[_Index]); } @@ -351,9 +351,6 @@ struct is_vector_impl> : std::true_type {}; template struct is_vector_impl> : std::true_type {}; -template -struct TableView; - template struct TableInfo { const char* name; @@ -462,8 +459,7 @@ struct TableInfo { std::string header_string = std::string(); for (uint32_t i = 0; i < sizeof...(Types); ++i) header_string += std::string(this->colrefs[i].name) + sep + '|' + sep; - const size_t l_sep = strlen(sep) + 1; - if (header_string.size() - l_sep >= 0) + if (const size_t l_sep = strlen(sep) + 1; header_string.size() >= l_sep) header_string.resize(header_string.size() - l_sep); header_string += end + std::string(header_string.size(), '=') + end; return header_string; @@ -535,7 +531,7 @@ struct TableInfo { } } template struct applier { - inline constexpr static void apply(const TableInfo& t, const char* __restrict sep = ",", const char* __restrict end = "\n", + constexpr static void apply(const TableInfo& t, const char* __restrict sep = ",", const char* __restrict end = "\n", const vector_type* __restrict view = nullptr, FILE* __restrict fp = nullptr, uint32_t limit = std::numeric_limits::max() ) {