customizable max thread history size

This commit is contained in:
Akash Mozumdar 2019-08-12 11:10:33 -04:00
parent 58f58b02d8
commit 749f8fa596
4 changed files with 6 additions and 1 deletions

View File

@ -72,7 +72,7 @@ void TextThread::Push(BYTE* data, int length)
void TextThread::Flush() void TextThread::Flush()
{ {
if (storage->size() > 10'000'000) storage->erase(0, 8'000'000); // https://github.com/Artikash/Textractor/issues/127#issuecomment-486882983 if (storage->size() > maxHistorySize) storage->erase(0, maxHistorySize / 2); // https://github.com/Artikash/Textractor/issues/127#issuecomment-486882983
std::deque<std::wstring> sentences; std::deque<std::wstring> sentences;
queuedSentences->swap(sentences); queuedSentences->swap(sentences);

View File

@ -12,6 +12,7 @@ public:
inline static bool filterRepetition = true; inline static bool filterRepetition = true;
inline static int flushDelay = 400; // flush every 400ms by default inline static int flushDelay = 400; // flush every 400ms by default
inline static int maxBufferSize = 1000; inline static int maxBufferSize = 1000;
inline static int maxHistorySize = 10'000'000;
TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring> name = {}); TextThread(ThreadParam tp, HookParam hp, std::optional<std::wstring> name = {});

View File

@ -48,6 +48,7 @@ extern const char* SHOW_SYSTEM_PROCESSES;
extern const char* DEFAULT_CODEPAGE; extern const char* DEFAULT_CODEPAGE;
extern const char* FLUSH_DELAY; extern const char* FLUSH_DELAY;
extern const char* MAX_BUFFER_SIZE; extern const char* MAX_BUFFER_SIZE;
extern const char* MAX_HISTORY_SIZE;
extern const wchar_t* ABOUT; extern const wchar_t* ABOUT;
extern const wchar_t* CL_OPTIONS; extern const wchar_t* CL_OPTIONS;
extern const wchar_t* LAUNCH_FAILED; extern const wchar_t* LAUNCH_FAILED;
@ -91,6 +92,7 @@ MainWindow::MainWindow(QWidget *parent) :
showSystemProcesses = settings.value(SHOW_SYSTEM_PROCESSES, showSystemProcesses).toBool(); showSystemProcesses = settings.value(SHOW_SYSTEM_PROCESSES, showSystemProcesses).toBool();
TextThread::flushDelay = settings.value(FLUSH_DELAY, TextThread::flushDelay).toInt(); TextThread::flushDelay = settings.value(FLUSH_DELAY, TextThread::flushDelay).toInt();
TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt(); TextThread::maxBufferSize = settings.value(MAX_BUFFER_SIZE, TextThread::maxBufferSize).toInt();
TextThread::maxHistorySize = settings.value(MAX_HISTORY_SIZE, TextThread::maxHistorySize).toInt();
Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt(); Host::defaultCodepage = settings.value(DEFAULT_CODEPAGE, Host::defaultCodepage).toInt();
Host::Start( Host::Start(
@ -535,6 +537,7 @@ void MainWindow::Settings()
for (auto [value, label] : Array<std::tuple<int&, const char*>>{ for (auto [value, label] : Array<std::tuple<int&, const char*>>{
{ TextThread::maxBufferSize, MAX_BUFFER_SIZE }, { TextThread::maxBufferSize, MAX_BUFFER_SIZE },
{ TextThread::flushDelay, FLUSH_DELAY }, { TextThread::flushDelay, FLUSH_DELAY },
{ TextThread::maxHistorySize, MAX_HISTORY_SIZE },
{ Host::defaultCodepage, DEFAULT_CODEPAGE }, { Host::defaultCodepage, DEFAULT_CODEPAGE },
}) })
{ {

View File

@ -74,6 +74,7 @@ const char* SHOW_SYSTEM_PROCESSES = u8"Show system processes";
const char* DEFAULT_CODEPAGE = u8"Default codepage"; const char* DEFAULT_CODEPAGE = u8"Default codepage";
const char* FLUSH_DELAY = u8"Flush delay"; const char* FLUSH_DELAY = u8"Flush delay";
const char* MAX_BUFFER_SIZE = u8"Max buffer size"; const char* MAX_BUFFER_SIZE = u8"Max buffer size";
const char* MAX_HISTORY_SIZE = u8"Max history size";
const wchar_t* CONSOLE = L"Console"; const wchar_t* CONSOLE = L"Console";
const wchar_t* CLIPBOARD = L"Clipboard"; const wchar_t* CLIPBOARD = L"Clipboard";
const wchar_t* ABOUT = L"Textractor " ARCH L" v" VERSION LR"( made by me: Artikash (email: akashmozumdar@gmail.com) const wchar_t* ABOUT = L"Textractor " ARCH L" v" VERSION LR"( made by me: Artikash (email: akashmozumdar@gmail.com)