blob: f045986e5e8ca7e738ad2bbd5448696b8a6129d4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "alignedmemory.h"
#include <stdint.h>
namespace vespalib {
AlignedMemory::AlignedMemory(size_t size, size_t align)
: _alloc(size == 0 ? 0 : new char[size + ((align > 1) ? (align - 1) : 0)]),
_align(_alloc)
{
if (align > 1) {
_align += (align - (((uintptr_t)_alloc) % align)) % align;
}
}
void
AlignedMemory::swap(AlignedMemory &rhs)
{
std::swap(_alloc, rhs._alloc);
std::swap(_align, rhs._align);
}
AlignedMemory::~AlignedMemory()
{
delete[] _alloc;
}
} // namespace search
|