From 0bdf1778cb60338abbbaf9fbdac3e5a983304448 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 12 Jan 2015 13:24:30 +0000 Subject: [PATCH] Some more memory tracking --- src/commands.cc | 8 +++++--- src/highlighter_group.hh | 2 +- src/highlighters.cc | 18 +++++++++--------- src/insert_completer.cc | 2 +- src/insert_completer.hh | 4 ++-- src/main.cc | 2 +- src/memory.hh | 2 ++ src/option_manager.hh | 21 +++++++++++++++++---- 8 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 34e14967..db0b6186 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -831,6 +831,8 @@ const CommandDesc debug_cmd = { write_debug("InternedString: " + to_string(UsedMemory::byte_count)); write_debug("BufferContent: " + to_string(UsedMemory::byte_count)); write_debug("BufferMeta: " + to_string(UsedMemory::byte_count)); + write_debug("Options: " + to_string(UsedMemory::byte_count)); + write_debug("Highlight: " + to_string(UsedMemory::byte_count)); write_debug("WordDB: " + to_string(UsedMemory::byte_count)); write_debug("Undefined: " + to_string(UsedMemory::byte_count)); write_debug("Malloced: " + to_string(mallinfo().uordblks)); @@ -949,11 +951,11 @@ const CommandDesc declare_option_cmd = { else if (parser[0] == "regex") opt = ®.declare_option(parser[1], docstring, Regex{}, flags); else if (parser[0] == "int-list") - opt = ®.declare_option>(parser[1], docstring, {}, flags); + opt = ®.declare_option>(parser[1], docstring, {}, flags); else if (parser[0] == "str-list") - opt = ®.declare_option>(parser[1], docstring, {}, flags); + opt = ®.declare_option>(parser[1], docstring, {}, flags); else if (parser[0] == "line-flag-list") - opt = ®.declare_option>(parser[1], docstring, {}, flags); + opt = ®.declare_option>(parser[1], docstring, {}, flags); else throw runtime_error("unknown type " + parser[0]); diff --git a/src/highlighter_group.hh b/src/highlighter_group.hh index 5430d4ad..9f813ccb 100644 --- a/src/highlighter_group.hh +++ b/src/highlighter_group.hh @@ -28,7 +28,7 @@ public: Completions complete_child(StringView path, ByteCount cursor_pos, bool group) const override; private: - using HighlighterMap = IdMap>; + using HighlighterMap = IdMap, MemoryDomain::Highlight>; HighlighterMap m_highlighters; }; diff --git a/src/highlighters.cc b/src/highlighters.cc index ed8e58b8..90ea4f96 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -72,7 +72,7 @@ void apply_highlighter(const Context& context, { using LineIterator = DisplayBuffer::LineList::iterator; LineIterator first_line; - std::vector insert_pos; + Vector insert_pos; auto line_end = display_buffer.lines().end(); DisplayBuffer region_display; @@ -159,7 +159,7 @@ auto apply_face = [](const Face& face) }; }; -using FacesSpec = std::vector; +using FacesSpec = Vector; static HighlighterAndId create_fill_highlighter(HighlighterParameters params) { @@ -271,7 +271,7 @@ private: { std::pair m_range; size_t m_timestamp = 0; - std::vector> m_matches; + Vector, MemoryDomain::Highlight> m_matches; }; BufferSideCache m_cache; @@ -716,7 +716,7 @@ struct RegexMatch ByteCoord begin_coord() const { return { line, begin }; } ByteCoord end_coord() const { return { line, end }; } }; -using RegexMatchList = std::vector; +using RegexMatchList = Vector; void find_matches(const Buffer& buffer, RegexMatchList& matches, const Regex& regex) { @@ -870,7 +870,7 @@ struct RegionDesc struct RegionsHighlighter : public Highlighter { public: - using NamedRegionDescList = std::vector>; + using NamedRegionDescList = Vector, MemoryDomain::Highlight>; RegionsHighlighter(NamedRegionDescList regions, String default_group) : m_regions{std::move(regions)}, m_default_group{std::move(default_group)} @@ -1005,7 +1005,7 @@ public: private: const NamedRegionDescList m_regions; const String m_default_group; - IdMap m_groups; + IdMap m_groups; struct Region { @@ -1013,13 +1013,13 @@ private: ByteCoord end; StringView group; }; - using RegionList = std::vector; + using RegionList = Vector; struct Cache { size_t timestamp = 0; - std::vector matches; - UnorderedMap regions; + Vector matches; + UnorderedMap regions; }; BufferSideCache m_cache; diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 3379c769..62ebed6e 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -15,7 +15,7 @@ namespace Kakoune { -using StringList = std::vector; +using StringList = Vector; String option_to_string(const InsertCompleterDesc& opt) { diff --git a/src/insert_completer.hh b/src/insert_completer.hh index 04cc49af..ffa2efdd 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -33,14 +33,14 @@ struct InsertCompleterDesc Optional param; }; -using InsertCompleterDescList = std::vector; +using InsertCompleterDescList = Vector; String option_to_string(const InsertCompleterDesc& opt); void option_from_string(StringView str, InsertCompleterDesc& opt); using ComplAndDesc = std::pair; -using ComplAndDescList = std::vector; +using ComplAndDescList = Vector; struct InsertCompletion { diff --git a/src/main.cc b/src/main.cc index 64001537..8c38e161 100644 --- a/src/main.cc +++ b/src/main.cc @@ -212,7 +212,7 @@ void register_options() reg.declare_option("path", "path to consider when trying to find a file", std::vector({ "./", "/usr/include" })); reg.declare_option("completers", "insert mode completers to execute.", - std::vector({ + InsertCompleterDescList({ InsertCompleterDesc{ InsertCompleterDesc::Filename }, InsertCompleterDesc{ InsertCompleterDesc::Word, "all"_str } }), OptionFlags::None); diff --git a/src/memory.hh b/src/memory.hh index af932b24..4d2d446f 100644 --- a/src/memory.hh +++ b/src/memory.hh @@ -15,6 +15,8 @@ enum class MemoryDomain InternedString, BufferContent, BufferMeta, + Options, + Highlight, WordDB }; diff --git a/src/option_manager.hh b/src/option_manager.hh index c1f9bd12..ad295fb4 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -7,6 +7,7 @@ #include "flags.hh" #include "option_types.hh" #include "regex.hh" +#include "vector.hh" namespace Kakoune { @@ -91,7 +92,7 @@ public: CandidateList complete_option_name(StringView prefix, ByteCount cursor_pos); - using OptionList = std::vector; + using OptionList = Vector; OptionList flatten_options() const; void register_watcher(OptionManagerWatcher& watcher); @@ -108,10 +109,10 @@ private: template CandidateList get_matching_names(MatchingFunc func); - std::vector> m_options; + Vector, MemoryDomain::Options> m_options; OptionManager* m_parent; - std::vector m_watchers; + Vector m_watchers; }; template @@ -153,6 +154,18 @@ public: { return new TypedOption{manager, m_desc, m_value}; } + + using Alloc = Allocator; + static void* operator new (std::size_t sz) + { + kak_assert(sz == sizeof(TypedOption)); + return Alloc{}.allocate(1); + } + + static void operator delete (void* ptr) + { + return Alloc{}.deallocate(reinterpret_cast(ptr), 1); + } private: T m_value; }; @@ -216,7 +229,7 @@ public: } private: OptionManager& m_global_manager; - std::vector> m_descs; + Vector, MemoryDomain::Options> m_descs; }; }