From 2a878d51fdfe5832a3b979dbc8e5b2144ad0d1f3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 14 Jan 2015 19:16:32 +0000 Subject: [PATCH] Even more memory tracking --- src/alias_registry.hh | 2 +- src/client.hh | 2 +- src/client_manager.hh | 2 +- src/commands.cc | 4 ++-- src/env_vars.hh | 2 +- src/face_registry.hh | 2 +- src/main.cc | 9 ++++++--- src/memory.hh | 12 ++++++++++++ src/option_types.hh | 8 ++++---- src/register_manager.cc | 6 +++--- src/register_manager.hh | 4 ++-- src/remote.cc | 18 +++++++++--------- src/user_interface.hh | 2 +- src/value.hh | 6 +++++- 14 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/alias_registry.hh b/src/alias_registry.hh index 1e292533..f29ee9e6 100644 --- a/src/alias_registry.hh +++ b/src/alias_registry.hh @@ -23,7 +23,7 @@ private: AliasRegistry() {} safe_ptr m_parent; - UnorderedMap m_aliases; + UnorderedMap m_aliases; }; } diff --git a/src/client.hh b/src/client.hh index 3a614314..85040ad4 100644 --- a/src/client.hh +++ b/src/client.hh @@ -70,7 +70,7 @@ private: DisplayLine m_pending_status_line; DisplayLine m_mode_line; - Vector m_pending_keys; + Vector m_pending_keys; }; } diff --git a/src/client_manager.hh b/src/client_manager.hh index 1d1147b5..fae31e00 100644 --- a/src/client_manager.hh +++ b/src/client_manager.hh @@ -49,7 +49,7 @@ private: String generate_name() const; Vector> m_clients; - Vector m_free_windows; + Vector m_free_windows; }; } diff --git a/src/commands.cc b/src/commands.cc index e9fc5fa2..af6b6167 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -30,7 +30,7 @@ #include #include -#if defined(__GLIBC__) +#if defined(__GLIBC__) || defined(__CYGWIN__) #include #endif @@ -838,7 +838,7 @@ const CommandDesc debug_cmd = { write_debug(" "_sv + domain_name((MemoryDomain)domain) + ": " + to_string(count)); } write_debug(" Total: " + to_string(total)); - #if defined(__GLIBC__) + #if defined(__GLIBC__) || defined(__CYGWIN__) write_debug(" Malloced: " + to_string(mallinfo().uordblks)); #endif } diff --git a/src/env_vars.hh b/src/env_vars.hh index cbab16ed..43bbe2de 100644 --- a/src/env_vars.hh +++ b/src/env_vars.hh @@ -7,7 +7,7 @@ namespace Kakoune { class String; -using EnvVarMap = UnorderedMap; +using EnvVarMap = UnorderedMap; EnvVarMap get_env_vars(); diff --git a/src/face_registry.hh b/src/face_registry.hh index 0d6a683a..67cb8b86 100644 --- a/src/face_registry.hh +++ b/src/face_registry.hh @@ -29,7 +29,7 @@ private: FaceOrAlias(Face face = Face{}) : face(face) {} }; - UnorderedMap m_aliases; + UnorderedMap m_aliases; }; inline Face get_face(const String& facedesc) diff --git a/src/main.cc b/src/main.cc index ae365cf5..15be8559 100644 --- a/src/main.cc +++ b/src/main.cc @@ -144,13 +144,16 @@ void register_env_vars() void register_registers() { - using StringList = Vector; + using StringList = Vector; static const struct { char name; StringList (*func)(const Context&); } dyn_regs[] = { { '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } }, - { '.', [](const Context& context) { return context.selections_content(); } }, + { '.', [](const Context& context) { + auto content = context.selections_content(); + return StringList{content.begin(), content.end()}; + } }, { '#', [](const Context& context) { StringList res; for (size_t i = 1; i < context.selections().size()+1; ++i) @@ -167,7 +170,7 @@ void register_registers() { register_manager.register_dynamic_register('0'+i, [i](const Context& context) { - Vector result; + StringList result; for (auto& sel : context.selections()) result.emplace_back(i < sel.captures().size() ? sel.captures()[i] : ""); return result; diff --git a/src/memory.hh b/src/memory.hh index 9c0ec462..f6ccb039 100644 --- a/src/memory.hh +++ b/src/memory.hh @@ -23,6 +23,12 @@ enum class MemoryDomain Mapping, Commands, Hooks, + Aliases, + EnvVars, + Faces, + Values, + Registers, + Client, WordDB, Count }; @@ -42,6 +48,12 @@ inline const char* domain_name(MemoryDomain domain) case MemoryDomain::Commands: return "Commands"; case MemoryDomain::Hooks: return "Hooks"; case MemoryDomain::WordDB: return "WordDB"; + case MemoryDomain::Aliases: return "Aliases"; + case MemoryDomain::EnvVars: return "EnvVars"; + case MemoryDomain::Faces: return "Faces"; + case MemoryDomain::Values: return "Values"; + case MemoryDomain::Registers: return "Registers"; + case MemoryDomain::Client: return "Client"; case MemoryDomain::Count: break; } kak_assert(false); diff --git a/src/option_types.hh b/src/option_types.hh index eda362f3..9151cd1c 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -67,8 +67,8 @@ bool option_add(Vector& opt, const Vector& vec) return not vec.empty(); } -template -String option_to_string(const UnorderedMap& opt) +template +String option_to_string(const UnorderedMap& opt) { String res; for (auto it = begin(opt); it != end(opt); ++it) @@ -82,8 +82,8 @@ String option_to_string(const UnorderedMap& opt) return res; } -template -void option_from_string(StringView str, UnorderedMap& opt) +template +void option_from_string(StringView str, UnorderedMap& opt) { opt.clear(); for (auto& elem : split(str, list_separator, '\\')) diff --git a/src/register_manager.cc b/src/register_manager.cc index c98c3964..af87dbb5 100644 --- a/src/register_manager.cc +++ b/src/register_manager.cc @@ -14,7 +14,7 @@ class StaticRegister : public Register public: Register& operator=(ArrayView values) override { - m_content = Vector(values.begin(), values.end()); + m_content = Vector(values.begin(), values.end()); return *this; } @@ -26,7 +26,7 @@ public: return ArrayView(m_content); } protected: - Vector m_content; + Vector m_content; static const String ms_empty; }; @@ -53,7 +53,7 @@ public: } private: - RegisterRetriever m_function; + RegisterRetriever m_function; }; Register& RegisterManager::operator[](StringView reg) diff --git a/src/register_manager.hh b/src/register_manager.hh index f8b891ee..52217374 100644 --- a/src/register_manager.hh +++ b/src/register_manager.hh @@ -11,7 +11,7 @@ namespace Kakoune { -using RegisterRetriever = std::function (const Context&)>; +using RegisterRetriever = std::function (const Context&)>; class RegisterManager : public Singleton { @@ -21,7 +21,7 @@ public: void register_dynamic_register(char reg, RegisterRetriever function); protected: - UnorderedMap> m_registers; + UnorderedMap, MemoryDomain::Registers> m_registers; }; } diff --git a/src/remote.cc b/src/remote.cc index b7d4cccf..e2aa10cc 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -75,14 +75,14 @@ public: write(val); } - template - void write(const Vector& vec) + template + void write(const Vector& vec) { write(ArrayView(vec)); } - template - void write(const UnorderedMap& map) + template + void write(const UnorderedMap& map) { write(map.size()); for (auto& val : map) @@ -229,11 +229,11 @@ DisplayBuffer read(int socket) return db; } -template -UnorderedMap read_map(int socket) +template +UnorderedMap read_map(int socket) { uint32_t size = read(socket); - UnorderedMap res; + UnorderedMap res; while (size--) { auto key = read(socket); @@ -519,7 +519,7 @@ void RemoteClient::process_next_message() m_ui->refresh(); break; case RemoteUIMsg::SetOptions: - m_ui->set_ui_options(read_map(socket)); + m_ui->set_ui_options(read_map(socket)); break; } } @@ -595,7 +595,7 @@ private: } if (c == 0) // end of initial command stream, go to interactive ui { - EnvVarMap env_vars = read_map(socket); + EnvVarMap env_vars = read_map(socket); std::unique_ptr ui{new RemoteUI{socket}}; ClientManager::instance().create_client(std::move(ui), std::move(env_vars), diff --git a/src/user_interface.hh b/src/user_interface.hh index a912b417..6734bf14 100644 --- a/src/user_interface.hh +++ b/src/user_interface.hh @@ -63,7 +63,7 @@ public: virtual void set_input_callback(InputCallback callback) = 0; - using Options = UnorderedMap; + using Options = UnorderedMap; virtual void set_ui_options(const Options& options) = 0; }; diff --git a/src/value.hh b/src/value.hh index e663513a..541da3d8 100644 --- a/src/value.hh +++ b/src/value.hh @@ -60,6 +60,10 @@ private: const std::type_info& type() const override { return typeid(T); } T m_content; + + using Alloc = Allocator, MemoryDomain::Values>; + static void* operator new (std::size_t sz) { return Alloc{}.allocate(1); } + static void operator delete (void* ptr) { Alloc{}.deallocate((Model*)ptr, 1); } }; std::unique_ptr m_value; @@ -78,7 +82,7 @@ struct ValueId : public StronglyTypedNumber inline size_t hash_value(ValueId val) { return hash_value((int)val); } -using ValueMap = UnorderedMap; +using ValueMap = UnorderedMap; }