Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/headless/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <spdlog/logger.h>
#include <spdlog/sinks/callback_sink.h>

#include <openvic-simulation/core/memory/MemoryTracker.hpp>
#include <openvic-simulation/core/memory/Vector.hpp>
#include <openvic-simulation/GameManager.hpp>
#include <openvic-simulation/country/CountryInstance.hpp>
#include <openvic-simulation/dataloader/Dataloader.hpp>
Expand All @@ -20,9 +22,7 @@
#include <openvic-simulation/economy/production/ResourceGatheringOperation.hpp>
#include <openvic-simulation/pathfinding/AStarPathing.hpp>
#include <openvic-simulation/testing/Testing.hpp>
#include <openvic-simulation/utility/Containers.hpp>
#include <openvic-simulation/utility/Logger.hpp>
#include <openvic-simulation/utility/MemoryTracker.hpp>

using namespace OpenVic;

Expand All @@ -37,7 +37,7 @@ inline static void print_memory_usage( //
#else
spdlog::source_loc {},
#endif
spdlog::level::info, "{} Memory Usage: {} Bytes", prefix, OpenVic::utility::MemoryTracker::get_memory_usage()
spdlog::level::info, "{} Memory Usage: {} Bytes", prefix, OpenVic::memory::MemoryTracker::get_memory_usage()
);
#endif
#endif
Expand Down Expand Up @@ -365,7 +365,7 @@ static bool run_headless(fs::path const& root, memory::vector<memory::string>& m
SPDLOG_INFO("===== Ending game session... =====");
ret &= game_manager.end_game_session();

SPDLOG_INFO("Max Memory Usage: {} Bytes", OpenVic::utility::MemoryTracker::get_max_memory_usage());
SPDLOG_INFO("Max Memory Usage: {} Bytes", OpenVic::memory::MemoryTracker::get_max_memory_usage());

return ret;
}
Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

#include <spdlog/spdlog.h>

#include <openvic-simulation/core/memory/String.hpp>
#include <openvic-simulation/core/memory/Vector.hpp>
#include "openvic-simulation/dataloader/Dataloader.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/utility/Logger.hpp"

using namespace OpenVic;
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/GameManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#include <optional>
#include <string_view>

#include "openvic-simulation/core/memory/Vector.hpp"
#include "openvic-simulation/DefinitionManager.hpp"
#include "openvic-simulation/InstanceManager.hpp"
#include "openvic-simulation/dataloader/ModManager.hpp"
#include "openvic-simulation/dataloader/Dataloader.hpp"
#include "openvic-simulation/misc/GameRulesManager.hpp"
#include "openvic-simulation/gen/commit_info.gen.hpp"
#include "openvic-simulation/utility/Containers.hpp"

#include <function2/function2.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/InstanceManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <function2/function2.hpp>

#include "openvic-simulation/core/memory/Vector.hpp"
#include "openvic-simulation/console/ConsoleInstance.hpp"
#include "openvic-simulation/country/CountryInstanceManager.hpp"
#include "openvic-simulation/country/CountryInstanceDeps.hpp"
Expand All @@ -23,7 +24,6 @@
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/FlagStrings.hpp"
#include "openvic-simulation/utility/ThreadPool.hpp"
#include "openvic-simulation/utility/Containers.hpp"

namespace OpenVic {

Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/console/ConsoleInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <fmt/format.h>

#include <openvic-simulation/core/memory/String.hpp>
#include <openvic-simulation/core/memory/Vector.hpp>
#include "openvic-simulation/DefinitionManager.hpp"
#include "openvic-simulation/InstanceManager.hpp"
#include "openvic-simulation/core/error/ErrorMacros.hpp"
Expand All @@ -21,7 +23,6 @@
#include "openvic-simulation/research/Technology.hpp"
#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/utility/Containers.hpp"

using namespace OpenVic;
using namespace std::string_view_literals;
Expand Down
3 changes: 2 additions & 1 deletion src/openvic-simulation/console/ConsoleInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include <fmt/color.h>
#include <fmt/core.h>

#include "openvic-simulation/core/memory/Formatting.hpp"
#include "openvic-simulation/core/memory/String.hpp"
#include "openvic-simulation/types/Colour.hpp"
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/utility/Containers.hpp"
#include "openvic-simulation/utility/Getters.hpp"

#include <function2/function2.hpp>
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/core/error/ErrorSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cstddef>

#include "openvic-simulation/core/error/Error.hpp"
#include "openvic-simulation/utility/Containers.hpp"
#include "openvic-simulation/core/memory/String.hpp"

namespace OpenVic {
// Set of all reported errors, if empty operates as if set to Error::OK
Expand Down
1 change: 0 additions & 1 deletion src/openvic-simulation/core/io/BMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <fmt/std.h>

#include "openvic-simulation/types/OrderedContainers.hpp"
#include "openvic-simulation/utility/Containers.hpp"
#include "openvic-simulation/utility/Logger.hpp"

using namespace OpenVic;
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/core/io/BMP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <fstream>
#include <span>

#include "openvic-simulation/utility/Containers.hpp"
#include "openvic-simulation/core/memory/Vector.hpp"

namespace OpenVic {
namespace fs = std::filesystem;
Expand Down
13 changes: 13 additions & 0 deletions src/openvic-simulation/core/memory/Colony.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <plf_colony.h>

#include <foonathan/memory/default_allocator.hpp>
#include <foonathan/memory/std_allocator.hpp>

#include "MemoryTracker.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "MemoryTracker.hpp"
#include "openvic-simulation/core/memory/MemoryTracker.hpp"


namespace OpenVic::memory {
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
using colony = plf::colony<T, foonathan::memory::std_allocator<T, tracker<RawAllocator>>>;
}
12 changes: 12 additions & 0 deletions src/openvic-simulation/core/memory/CowPtr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <foonathan/memory/default_allocator.hpp>
#include <foonathan/memory/std_allocator.hpp>

#include "openvic-simulation/types/CowPtr.hpp"
#include "MemoryTracker.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "MemoryTracker.hpp"
#include "openvic-simulation/core/memory/MemoryTracker.hpp"


namespace OpenVic::memory {
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
using cow_ptr = cow_ptr<T, foonathan::memory::std_allocator<T, tracker<RawAllocator>>>;
}
12 changes: 12 additions & 0 deletions src/openvic-simulation/core/memory/CowVector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <foonathan/memory/default_allocator.hpp>
#include <foonathan/memory/std_allocator.hpp>

#include "openvic-simulation/types/CowVector.hpp"
#include "MemoryTracker.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "MemoryTracker.hpp"
#include "openvic-simulation/core/memory/MemoryTracker.hpp"


namespace OpenVic::memory {
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
using cow_vector = cow_vector<T, foonathan::memory::std_allocator<T, tracker<RawAllocator>>>;
}
29 changes: 29 additions & 0 deletions src/openvic-simulation/core/memory/Deque.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <scoped_allocator>

#include <foonathan/memory/config.hpp>
#include <foonathan/memory/std_allocator.hpp>

#include "openvic-simulation/core/portable/Deque.hpp"
#include "MemoryTracker.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "MemoryTracker.hpp"
#include "openvic-simulation/core/memory/MemoryTracker.hpp"


namespace OpenVic::memory {
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
FOONATHAN_ALIAS_TEMPLATE(
deque,
OpenVic::utility::deque<
T,
foonathan::memory::std_allocator<T, tracker<RawAllocator>>
>
);

template<typename T, class RawAllocator = foonathan::memory::default_allocator>
FOONATHAN_ALIAS_TEMPLATE(
deque_scoped_alloc,
OpenVic::utility::deque<
T,
std::scoped_allocator_adaptor<foonathan::memory::std_allocator<T, tracker<RawAllocator>>>
>
);
}
34 changes: 34 additions & 0 deletions src/openvic-simulation/core/memory/Formatting.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <fmt/base.h>
#include <fmt/format.h>

#include <foonathan/memory/default_allocator.hpp>

#include "MemoryTracker.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "MemoryTracker.hpp"
#include "openvic-simulation/core/memory/MemoryTracker.hpp"

#include "String.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "String.hpp"
#include "openvic-simulation/core/memory/String.hpp"


namespace OpenVic::memory {
namespace fmt {
template<typename T, class RawAllocator = foonathan::memory::default_allocator>
using basic_memory_buffer = ::fmt::basic_memory_buffer<
T,
::fmt::inline_buffer_size,
foonathan::memory::std_allocator<
T,
OpenVic::memory::tracker<RawAllocator>
>
>;

inline static memory::string vformat(::fmt::string_view fmt, ::fmt::format_args args) {
memory::fmt::basic_memory_buffer<char> buf {};
::fmt::vformat_to(std::back_inserter(buf), fmt, args);
return memory::string(buf.data(), buf.size());
}

template<typename... Args>
memory::string format(::fmt::string_view fmt, const Args&... args) {
return memory::fmt::vformat(fmt, ::fmt::make_format_args(args...));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <foonathan/memory/tracking.hpp>

namespace OpenVic::utility {
namespace OpenVic::memory {
struct MemoryTracker {
void on_node_allocation(void* mem, std::size_t size, std::size_t) {
uint64_t new_mem_usage = _memory_usage.fetch_add(size, std::memory_order_acq_rel) + size;
Expand Down Expand Up @@ -53,7 +53,7 @@ namespace OpenVic::memory {
template<class RawAllocator>
using tracker =
#ifdef DEBUG_ENABLED
foonathan::memory::tracked_allocator<OpenVic::utility::MemoryTracker, RawAllocator>
foonathan::memory::tracked_allocator<OpenVic::memory::MemoryTracker, RawAllocator>
#else
RawAllocator
#endif
Expand Down
10 changes: 10 additions & 0 deletions src/openvic-simulation/core/memory/Queue.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

#include <queue>

#include "Deque.hpp"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "Deque.hpp"
#include "openvic-simulation/core/memory/Deque.hpp"


namespace OpenVic::memory {
template<typename T, typename Container = memory::deque<T>>
using queue = std::queue<T, Container>;
}
Loading
Loading