mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-14 23:07:58 +02:00
Ported #962 to C++.
Improved alignment calculation logic. Fixed test for zone. Now, align parameter must be 2^n (n >=0). e.g. 1,2,4,8,16, ...
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
@@ -230,10 +232,11 @@ inline zone::zone(size_t chunk_size) noexcept:m_chunk_size(chunk_size), m_chunk_
|
||||
|
||||
inline char* zone::get_aligned(char* ptr, size_t align)
|
||||
{
|
||||
BOOST_ASSERT(align != 0 && (align & (align - 1)) == 0); // align must be 2^n (n >= 0)
|
||||
return
|
||||
reinterpret_cast<char*>(
|
||||
reinterpret_cast<size_t>(
|
||||
(ptr + (align - 1))) / align * align);
|
||||
reinterpret_cast<uintptr_t>(ptr + (align - 1)) & ~static_cast<uintptr_t>(align - 1)
|
||||
);
|
||||
}
|
||||
|
||||
inline void* zone::allocate_align(size_t size, size_t align)
|
||||
|
Reference in New Issue
Block a user