mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
fix small heap alignment violations
This commit is contained in:
parent
26d4801da4
commit
2d8b50e198
1 changed files with 12 additions and 7 deletions
|
|
@ -11,8 +11,10 @@
|
|||
|
||||
namespace util {
|
||||
template<typename T>
|
||||
inline T read_int_le(const uint8_t* src, size_t offset=0) {
|
||||
return dataio::le2h(*(reinterpret_cast<const T*>(src) + offset));
|
||||
inline T read_int_le(const uint8_t* src, ptrdiff_t offset=0) {
|
||||
T tmp;
|
||||
std::memcpy(&tmp, src + offset * sizeof(T), sizeof(T));
|
||||
return dataio::le2h(tmp);
|
||||
}
|
||||
|
||||
/// @brief Simple heap implementation for memory-optimal sparse array of
|
||||
|
|
@ -87,8 +89,7 @@ namespace util {
|
|||
std::memset(found, 0, entrySize);
|
||||
return found;
|
||||
}
|
||||
this->free(found);
|
||||
return allocate(index, size);
|
||||
free(found);
|
||||
}
|
||||
for (size_t i = 0; i < entriesCount; i++) {
|
||||
auto data = buffer.data() + offset;
|
||||
|
|
@ -110,9 +111,12 @@ namespace util {
|
|||
entriesCount++;
|
||||
|
||||
auto data = buffer.data() + offset;
|
||||
*reinterpret_cast<Tindex*>(data) = dataio::h2le(index);
|
||||
|
||||
Tindex indexTmp = dataio::h2le(index);
|
||||
Tsize sizeTmp = dataio::h2le(size);
|
||||
std::memcpy(data, &indexTmp, sizeof(Tindex));
|
||||
data += sizeof(Tindex);
|
||||
*reinterpret_cast<Tsize*>(data) = dataio::h2le(size);
|
||||
std::memcpy(data, &sizeTmp, sizeof(Tsize));
|
||||
return data + sizeof(Tsize);
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +151,8 @@ namespace util {
|
|||
ubyte* dst = out.data();
|
||||
const ubyte* src = buffer.data();
|
||||
|
||||
*reinterpret_cast<Tindex*>(dst) = dataio::h2le(entriesCount);
|
||||
Tindex countTmp = dataio::h2le(entriesCount);
|
||||
std::memcpy(dst, &countTmp, sizeof(Tindex));
|
||||
dst += sizeof(Tindex);
|
||||
|
||||
std::memcpy(dst, src, buffer.size());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue