Allocate exactly specified size in ArrayAllocator.
This commit is contained in:
parent
42ca2dcef5
commit
67aa9cad66
@ -19,16 +19,11 @@ class ArrayAllocator final : public StackAllocator::AllocatorImpl {
|
|||||||
size_t pos{0};
|
size_t pos{0};
|
||||||
|
|
||||||
MutableSlice allocate(size_t size) final {
|
MutableSlice allocate(size_t size) final {
|
||||||
if (size == 0) {
|
if (size > MEM_SIZE) {
|
||||||
size = 8;
|
std::abort(); // too much memory requested
|
||||||
} else {
|
|
||||||
if (size > MEM_SIZE) {
|
|
||||||
std::abort(); // too much memory requested
|
|
||||||
}
|
|
||||||
size = (size + 7) & -8;
|
|
||||||
}
|
}
|
||||||
char *res = mem.data() + pos;
|
char *res = mem.data() + pos;
|
||||||
pos += size;
|
pos += (size + 7) & -8;
|
||||||
if (pos > MEM_SIZE) {
|
if (pos > MEM_SIZE) {
|
||||||
std::abort(); // memory is over
|
std::abort(); // memory is over
|
||||||
}
|
}
|
||||||
@ -36,6 +31,7 @@ class ArrayAllocator final : public StackAllocator::AllocatorImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void free_ptr(char *ptr, size_t size) final {
|
void free_ptr(char *ptr, size_t size) final {
|
||||||
|
size = (size + 7) & -8;
|
||||||
if (size > pos || ptr != mem.data() + (pos - size)) {
|
if (size > pos || ptr != mem.data() + (pos - size)) {
|
||||||
std::abort(); // shouldn't happen
|
std::abort(); // shouldn't happen
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user