Pass continuations for success and failure cases (#788)
This PR provides a templated parameter to the allocation routines. This can be used to add special behaviour in both the successful allocation behaviour, and in the failing to allocate cases. The intent of this is two enable two future features * set_new_handler - so that the failure case doesn't just set ENOMEM, and return nullptr. But can handle both the Windows and C++ versions of (_)set_new_handler. * The success handler can be used to add checking, zeroing and in the future storing precise size information in metadata for each allocation.
This commit is contained in:
committed by
GitHub
parent
012138e29f
commit
d4c7e01cd7
@@ -166,7 +166,7 @@ void snmalloc_random_walk(
|
||||
case EventKind::AllocZero:
|
||||
{
|
||||
auto ptr =
|
||||
static_cast<char*>(scoped->alloc<snmalloc::YesZero>(e.size_or_index));
|
||||
static_cast<char*>(scoped->alloc<snmalloc::Zero>(e.size_or_index));
|
||||
results.emplace_back(0, ptr, e.size_or_index);
|
||||
break;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ void snmalloc_random_walk(
|
||||
case EventKind::AllocNoZero:
|
||||
{
|
||||
auto ptr =
|
||||
static_cast<char*>(scoped->alloc<snmalloc::NoZero>(e.size_or_index));
|
||||
static_cast<char*>(scoped->alloc<snmalloc::Uninit>(e.size_or_index));
|
||||
std::fill(ptr, ptr + e.size_or_index, e.filler);
|
||||
results.emplace_back(e.filler, ptr, e.size_or_index);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user