From b2eaf63a6e5a1a2cd100e16c89e3abae4eacbee9 Mon Sep 17 00:00:00 2001 From: Michael Liebmann Date: Tue, 6 Sep 2016 11:30:06 +0200 Subject: [PATCH] CFileHelpers: Rework FileBuf handling FileBuf: Reserve memory only when it is needed (copyFile) copyFile: Reserve for small files, only as much memory as is required Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/0a1cdb3d4ec79affe562968f551a566dac43a395 Author: Michael Liebmann Date: 2016-09-06 (Tue, 06 Sep 2016) ------------------ This commit was generated by Migit --- src/system/helpers.cpp | 17 +++++++++++++++-- src/system/helpers.h | 5 +++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/system/helpers.cpp b/src/system/helpers.cpp index 39f49efcd..26d2bbab5 100644 --- a/src/system/helpers.cpp +++ b/src/system/helpers.cpp @@ -675,8 +675,21 @@ CFileHelpers::CFileHelpers() CFileHelpers::~CFileHelpers() { - if (FileBuf != NULL) - delete [] FileBuf; +} + +char* CFileHelpers::initFileBuf(char* buf, uint32_t size) +{ + if (buf == NULL) + buf = new char[size]; + return buf; +} + +char* CFileHelpers::deleteFileBuf(char* buf) +{ + if (buf != NULL) + delete [] buf; + buf = NULL; + return buf; } CFileHelpers* CFileHelpers::getInstance() diff --git a/src/system/helpers.h b/src/system/helpers.h index 7e8aa51f5..811695650 100644 --- a/src/system/helpers.h +++ b/src/system/helpers.h @@ -86,10 +86,11 @@ struct helpersDebugInfo { class CFileHelpers { private: - unsigned long FileBufSize; - char *FileBuf; + uint32_t FileBufMaxSize; int fd1, fd2; + char* initFileBuf(char* buf, uint32_t size); + char* deleteFileBuf(char* buf); bool ConsoleQuiet; helpersDebugInfo DebugInfo; void setDebugInfo(const char* msg, const char* file, const char* func, int line);