// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
void* Alloc(j_common_ptr cinfo, int pool_id, size_t sizeofobject) {
MemoryManager* mem = reinterpret_cast<MemoryManager*>(cinfo->mem); if (pool_id < 0 || pool_id >= 2 * JPOOL_NUMPOOLS) {
JPEGLI_ERROR("Invalid pool id %d", pool_id);
} if (mem->pub.max_memory_to_use > 0 &&
mem->total_memory_usage + static_cast<uint64_t>(sizeofobject) > static_cast<uint64_t>(mem->pub.max_memory_to_use)) {
JPEGLI_ERROR("Total memory usage exceeding %ld",
mem->pub.max_memory_to_use);
} void* p; if (pool_id < JPOOL_NUMPOOLS) {
p = malloc(sizeofobject);
} else {
p = hwy::AllocateAlignedBytes(sizeofobject, nullptr, nullptr);
} if (p == nullptr) {
JPEGLI_ERROR("Out of memory");
}
mem->owned_ptrs[pool_id].push_back(p);
mem->pool_memory_usage[pool_id] += sizeofobject;
mem->total_memory_usage += sizeofobject;
mem->peak_memory_usage =
std::max(mem->peak_memory_usage, mem->total_memory_usage); return p;
}
constexpr size_t gcd(size_t a, size_t b) { return b == 0 ? a : gcd(b, a % b); }
constexpr size_t lcm(size_t a, size_t b) { return (a * b) / gcd(a, b); }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.