scratch space

master
Bill 2 years ago
parent e588e4b0dc
commit a91ab1841d

@ -683,6 +683,8 @@ class groupby_c(ast_node):
else: else:
gscanner.add(f'{ce[0]}.emplace_back({get_var_names_ex(ex)});\n') gscanner.add(f'{ce[0]}.emplace_back({get_var_names_ex(ex)});\n')
gscanner.add(f'GC::scratch_space->release();')
gscanner.finalize() gscanner.finalize()
self.context.emitc(f'GC::scratch_space = nullptr;') self.context.emitc(f'GC::scratch_space = nullptr;')

@ -82,7 +82,7 @@ public:
start_deamon(); start_deamon();
GC::gc_handle = this; GC::gc_handle = this;
this->scratch.init(scratch_sz); this->scratch.init(1);
} // 256 MB } // 256 MB
~GC(){ ~GC(){

@ -480,8 +480,8 @@ void ScratchSpace::init(size_t initial_capacity) {
} }
inline void* ScratchSpace::alloc(uint32_t sz){ inline void* ScratchSpace::alloc(uint32_t sz){
this->cnt += sz; // major cost
ptr = this->cnt; ptr = this->cnt;
this->cnt += sz; // major cost
if (this->cnt > capacity) { if (this->cnt > capacity) {
[[unlikely]] [[unlikely]]
capacity = this->cnt + (capacity >> 1); capacity = this->cnt + (capacity >> 1);
@ -499,14 +499,13 @@ inline void ScratchSpace::register_ret(void* ret){
inline void ScratchSpace::release(){ inline void ScratchSpace::release(){
ptr = cnt = 0; ptr = cnt = 0;
ret = nullptr;
auto vec_tmpmem_fractions = auto vec_tmpmem_fractions =
static_cast<vector_type<void*>*>(temp_memory_fractions); static_cast<vector_type<void*>*>(temp_memory_fractions);
if (vec_tmpmem_fractions->size) { if (vec_tmpmem_fractions->size) {
//[[unlikely]] [[unlikely]]
for(auto& mem : *vec_tmpmem_fractions){ for(auto& mem : *vec_tmpmem_fractions){
free(mem); //free(mem);
//GC::gc_handle->reg(mem); GC::gc_handle->reg(mem);
} }
vec_tmpmem_fractions->clear(); vec_tmpmem_fractions->clear();
} }
@ -514,6 +513,7 @@ inline void ScratchSpace::release(){
inline void ScratchSpace::reset() { inline void ScratchSpace::reset() {
this->release(); this->release();
ret = nullptr;
if (capacity != initial_capacity){ if (capacity != initial_capacity){
capacity = initial_capacity; capacity = initial_capacity;
scratchspace = static_cast<char*>(realloc(scratchspace, capacity)); scratchspace = static_cast<char*>(realloc(scratchspace, capacity));

@ -75,11 +75,11 @@ void Server::connect(Context *cxt){
printf("Error: Server %p already connected. Restart? (Y/n). \n", server); printf("Error: Server %p already connected. Restart? (Y/n). \n", server);
char c[50]; char c[50];
std::cin.getline(c, 49); 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'){ if (!c[i] || c[i] == 'y' || c[i] == 'Y'){
monetdbe_close(*server); monetdbe_close(*server);
free(*server); free(*server);
this->server = 0; this->server = nullptr;
break; break;
} }
else if(c[i]&&!(c[i] == ' ' || c[i] == '\t')) 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]; szs [i] = monetdbe_type_szs[cols[i]->type];
header_string = header_string + cols[i]->name + sep + '|' + sep; header_string = header_string + cols[i]->name + sep + '|' + sep;
} }
const size_t l_sep = strlen(sep) + 1; if (const size_t l_sep = strlen(sep) + 1; header_string.size() >= l_sep)
if (header_string.size() - l_sep >= 0)
header_string.resize(header_string.size() - l_sep); header_string.resize(header_string.size() - l_sep);
header_string += end + std::string(header_string.size(), '=') + end; header_string += end + std::string(header_string.size(), '=') + end;
fputs(header_string.c_str(), stdout); fputs(header_string.c_str(), stdout);

@ -332,7 +332,7 @@ template<class ...Types> struct TableInfo;
template<class ...Types> struct TableView; template<class ...Types> struct TableView;
template <long long _Index, bool order = true, class... _Types> template <long long _Index, bool order = true, class... _Types>
constexpr inline auto& get(const TableInfo<_Types...>& table) noexcept { constexpr auto& get(const TableInfo<_Types...>& table) noexcept {
if constexpr (order) if constexpr (order)
return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.colrefs[_Index]); return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.colrefs[_Index]);
else else
@ -340,7 +340,7 @@ constexpr inline auto& get(const TableInfo<_Types...>& table) noexcept {
} }
template <long long _Index, class... _Types> template <long long _Index, class... _Types>
constexpr inline ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>>& get(const TableView<_Types...>& table) noexcept { constexpr ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>>& get(const TableView<_Types...>& table) noexcept {
return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.info.colrefs[_Index]); return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.info.colrefs[_Index]);
} }
@ -351,9 +351,6 @@ struct is_vector_impl<ColView<V>> : std::true_type {};
template <class V> template <class V>
struct is_vector_impl<vector_type<V>> : std::true_type {}; struct is_vector_impl<vector_type<V>> : std::true_type {};
template<class ...Types>
struct TableView;
template<class ...Types> template<class ...Types>
struct TableInfo { struct TableInfo {
const char* name; const char* name;
@ -462,8 +459,7 @@ struct TableInfo {
std::string header_string = std::string(); std::string header_string = std::string();
for (uint32_t i = 0; i < sizeof...(Types); ++i) for (uint32_t i = 0; i < sizeof...(Types); ++i)
header_string += std::string(this->colrefs[i].name) + sep + '|' + sep; header_string += std::string(this->colrefs[i].name) + sep + '|' + sep;
const size_t l_sep = strlen(sep) + 1; if (const size_t l_sep = strlen(sep) + 1; header_string.size() >= l_sep)
if (header_string.size() - l_sep >= 0)
header_string.resize(header_string.size() - l_sep); header_string.resize(header_string.size() - l_sep);
header_string += end + std::string(header_string.size(), '=') + end; header_string += end + std::string(header_string.size(), '=') + end;
return header_string; return header_string;
@ -535,7 +531,7 @@ struct TableInfo {
} }
} }
template <int ...vals> struct applier { template <int ...vals> struct applier {
inline constexpr static void apply(const TableInfo<Types...>& t, const char* __restrict sep = ",", const char* __restrict end = "\n", constexpr static void apply(const TableInfo<Types...>& t, const char* __restrict sep = ",", const char* __restrict end = "\n",
const vector_type<uint32_t>* __restrict view = nullptr, FILE* __restrict fp = nullptr, uint32_t limit = std::numeric_limits<uint32_t>::max() const vector_type<uint32_t>* __restrict view = nullptr, FILE* __restrict fp = nullptr, uint32_t limit = std::numeric_limits<uint32_t>::max()
) )
{ {

Loading…
Cancel
Save