Some more memory tracking

This commit is contained in:
Maxime Coste 2015-01-12 13:24:30 +00:00
parent dedb16bc73
commit 0bdf1778cb
8 changed files with 38 additions and 21 deletions

View File

@ -831,6 +831,8 @@ const CommandDesc debug_cmd = {
write_debug("InternedString: " + to_string(UsedMemory<MemoryDomain::InternedString>::byte_count));
write_debug("BufferContent: " + to_string(UsedMemory<MemoryDomain::BufferContent>::byte_count));
write_debug("BufferMeta: " + to_string(UsedMemory<MemoryDomain::BufferMeta>::byte_count));
write_debug("Options: " + to_string(UsedMemory<MemoryDomain::Options>::byte_count));
write_debug("Highlight: " + to_string(UsedMemory<MemoryDomain::Highlight>::byte_count));
write_debug("WordDB: " + to_string(UsedMemory<MemoryDomain::WordDB>::byte_count));
write_debug("Undefined: " + to_string(UsedMemory<MemoryDomain::Undefined>::byte_count));
write_debug("Malloced: " + to_string(mallinfo().uordblks));
@ -949,11 +951,11 @@ const CommandDesc declare_option_cmd = {
else if (parser[0] == "regex")
opt = &reg.declare_option<Regex>(parser[1], docstring, Regex{}, flags);
else if (parser[0] == "int-list")
opt = &reg.declare_option<std::vector<int>>(parser[1], docstring, {}, flags);
opt = &reg.declare_option<Vector<int, MemoryDomain::Options>>(parser[1], docstring, {}, flags);
else if (parser[0] == "str-list")
opt = &reg.declare_option<std::vector<String>>(parser[1], docstring, {}, flags);
opt = &reg.declare_option<Vector<String, MemoryDomain::Options>>(parser[1], docstring, {}, flags);
else if (parser[0] == "line-flag-list")
opt = &reg.declare_option<std::vector<LineAndFlag>>(parser[1], docstring, {}, flags);
opt = &reg.declare_option<Vector<LineAndFlag, MemoryDomain::Options>>(parser[1], docstring, {}, flags);
else
throw runtime_error("unknown type " + parser[0]);

View File

@ -28,7 +28,7 @@ public:
Completions complete_child(StringView path, ByteCount cursor_pos, bool group) const override;
private:
using HighlighterMap = IdMap<std::unique_ptr<Highlighter>>;
using HighlighterMap = IdMap<std::unique_ptr<Highlighter>, MemoryDomain::Highlight>;
HighlighterMap m_highlighters;
};

View File

@ -72,7 +72,7 @@ void apply_highlighter(const Context& context,
{
using LineIterator = DisplayBuffer::LineList::iterator;
LineIterator first_line;
std::vector<DisplayLine::iterator> insert_pos;
Vector<DisplayLine::iterator> 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<String>;
using FacesSpec = Vector<String, MemoryDomain::Highlight>;
static HighlighterAndId create_fill_highlighter(HighlighterParameters params)
{
@ -271,7 +271,7 @@ private:
{
std::pair<LineCount, LineCount> m_range;
size_t m_timestamp = 0;
std::vector<std::vector<BufferRange>> m_matches;
Vector<Vector<BufferRange, MemoryDomain::Highlight>, MemoryDomain::Highlight> m_matches;
};
BufferSideCache<Cache> 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<RegexMatch>;
using RegexMatchList = Vector<RegexMatch, MemoryDomain::Highlight>;
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<std::pair<String, RegionDesc>>;
using NamedRegionDescList = Vector<std::pair<String, RegionDesc>, 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<HighlighterGroup> m_groups;
IdMap<HighlighterGroup, MemoryDomain::Highlight> m_groups;
struct Region
{
@ -1013,13 +1013,13 @@ private:
ByteCoord end;
StringView group;
};
using RegionList = std::vector<Region>;
using RegionList = Vector<Region, MemoryDomain::Highlight>;
struct Cache
{
size_t timestamp = 0;
std::vector<RegionMatches> matches;
UnorderedMap<BufferRange, RegionList> regions;
Vector<RegionMatches, MemoryDomain::Highlight> matches;
UnorderedMap<BufferRange, RegionList, MemoryDomain::Highlight> regions;
};
BufferSideCache<Cache> m_cache;

View File

@ -15,7 +15,7 @@
namespace Kakoune
{
using StringList = std::vector<String>;
using StringList = Vector<String, MemoryDomain::Options>;
String option_to_string(const InsertCompleterDesc& opt)
{

View File

@ -33,14 +33,14 @@ struct InsertCompleterDesc
Optional<String> param;
};
using InsertCompleterDescList = std::vector<InsertCompleterDesc>;
using InsertCompleterDescList = Vector<InsertCompleterDesc, MemoryDomain::Options>;
String option_to_string(const InsertCompleterDesc& opt);
void option_from_string(StringView str, InsertCompleterDesc& opt);
using ComplAndDesc = std::pair<String, String>;
using ComplAndDescList = std::vector<ComplAndDesc>;
using ComplAndDescList = Vector<ComplAndDesc>;
struct InsertCompletion
{

View File

@ -212,7 +212,7 @@ void register_options()
reg.declare_option("path", "path to consider when trying to find a file",
std::vector<String>({ "./", "/usr/include" }));
reg.declare_option("completers", "insert mode completers to execute.",
std::vector<InsertCompleterDesc>({
InsertCompleterDescList({
InsertCompleterDesc{ InsertCompleterDesc::Filename },
InsertCompleterDesc{ InsertCompleterDesc::Word, "all"_str }
}), OptionFlags::None);

View File

@ -15,6 +15,8 @@ enum class MemoryDomain
InternedString,
BufferContent,
BufferMeta,
Options,
Highlight,
WordDB
};

View File

@ -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<const Option*>;
using OptionList = Vector<const Option*>;
OptionList flatten_options() const;
void register_watcher(OptionManagerWatcher& watcher);
@ -108,10 +109,10 @@ private:
template<typename MatchingFunc>
CandidateList get_matching_names(MatchingFunc func);
std::vector<std::unique_ptr<Option>> m_options;
Vector<std::unique_ptr<Option>, MemoryDomain::Options> m_options;
OptionManager* m_parent;
std::vector<OptionManagerWatcher*> m_watchers;
Vector<OptionManagerWatcher*, MemoryDomain::Options> m_watchers;
};
template<typename T>
@ -153,6 +154,18 @@ public:
{
return new TypedOption{manager, m_desc, m_value};
}
using Alloc = Allocator<TypedOption, MemoryDomain::Options>;
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<TypedOption*>(ptr), 1);
}
private:
T m_value;
};
@ -216,7 +229,7 @@ public:
}
private:
OptionManager& m_global_manager;
std::vector<std::unique_ptr<OptionDesc>> m_descs;
Vector<std::unique_ptr<OptionDesc>, MemoryDomain::Options> m_descs;
};
}