scratch space

master
Bill 2 years ago
parent e588e4b0dc
commit a91ab1841d

@ -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;')

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

@ -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<vector_type<void*>*>(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<char*>(realloc(scratchspace, capacity));

@ -79,7 +79,7 @@ void Server::connect(Context *cxt){
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);

@ -332,7 +332,7 @@ template<class ...Types> struct TableInfo;
template<class ...Types> struct TableView;
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)
return *(ColRef<std::tuple_element_t<_Index, std::tuple<_Types...>>> *) & (table.colrefs[_Index]);
else
@ -340,7 +340,7 @@ constexpr inline auto& get(const TableInfo<_Types...>& table) noexcept {
}
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]);
}
@ -351,9 +351,6 @@ struct is_vector_impl<ColView<V>> : std::true_type {};
template <class V>
struct is_vector_impl<vector_type<V>> : std::true_type {};
template<class ...Types>
struct TableView;
template<class ...Types>
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 <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()
)
{

Loading…
Cancel
Save