commit e501ddf1339da4d61531ec7668161bd2b1f1566c
parent aa41a7d1a4b0fafafb706ad58c284d88ba91cbd2
Author: dsp56300 <dsp56300@users.noreply.github.com>
Date: Thu, 12 Sep 2024 20:08:17 +0200
use heap alloc instead of stack alloc for rom data
Diffstat:
4 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/source/nord/n2x/n2xLib/n2xrom.cpp b/source/nord/n2x/n2xLib/n2xrom.cpp
@@ -18,10 +18,13 @@ namespace n2x
invalidate();
}
- bool Rom::isValidRom(std::array<unsigned char, 524288>& _data)
+ bool Rom::isValidRom(const std::vector<uint8_t>& _data)
{
constexpr uint8_t key[] = {'n', 'r', '2', 0, 'n', 'L', '2', 0};
+ if(_data.size() < std::size(key))
+ return false;
+
const auto it = std::search(_data.begin(), _data.end(), std::begin(key), std::end(key));
return it != _data.end();
}
diff --git a/source/nord/n2x/n2xLib/n2xrom.h b/source/nord/n2x/n2xLib/n2xrom.h
@@ -11,6 +11,6 @@ namespace n2x
Rom();
Rom(const std::string& _filename);
- static bool isValidRom(std::array<uint8_t, g_romSize>& _data);
+ static bool isValidRom(const std::vector<uint8_t>& _data);
};
}
diff --git a/source/nord/n2x/n2xLib/n2xromdata.cpp b/source/nord/n2x/n2xLib/n2xromdata.cpp
@@ -14,16 +14,14 @@ namespace n2x
{
if(_filename.empty())
return;
- std::vector<uint8_t> data;
- if(!synthLib::readFile(data, _filename))
+ if(!synthLib::readFile(m_data, _filename))
return;
- if(data.size() != m_data.size())
+ if(m_data.size() != MySize)
return;
- std::copy(data.begin(), data.end(), m_data.begin());
m_filename = _filename;
}
- template <uint32_t Size> void RomData<Size>::saveAs(const std::string& _filename)
+ template <uint32_t Size> void RomData<Size>::saveAs(const std::string& _filename) const
{
synthLib::writeFile(_filename, m_data);
}
diff --git a/source/nord/n2x/n2xLib/n2xromdata.h b/source/nord/n2x/n2xLib/n2xromdata.h
@@ -1,8 +1,8 @@
#pragma once
-#include <array>
#include <cstdint>
#include <string>
+#include <vector>
namespace n2x
{
@@ -18,7 +18,7 @@ namespace n2x
const auto& data() const { return m_data; }
auto& data() { return m_data; }
- void saveAs(const std::string& _filename);
+ void saveAs(const std::string& _filename) const;
const auto& getFilename() const { return m_filename; }
@@ -27,7 +27,7 @@ namespace n2x
m_filename.clear();
}
private:
- std::array<uint8_t, Size> m_data;
+ std::vector<uint8_t> m_data;
std::string m_filename;
};
}