Drop custom "new" operator overloads

This commit is contained in:
kayomn 2023-03-02 19:46:59 +00:00
parent 5755cc6517
commit 7876efc4f5

View File

@ -223,72 +223,6 @@ export namespace coral {
}
}
/**
* Allocates and initializes a type of `requested_size` in `buffer`, returning its base pointer. As a result of
* accepting a pre-allocated buffer, invocation does not allocate any dynamic memory.
*
* *Note*: passing an `buffer` smaller than `requested_size` will result in safety-checked behavior.
*/
export void * operator new(coral::usize requested_size, coral::slice<coral::u8> const & buffer) {
if (buffer.length < requested_size) coral::unreachable();
return buffer.pointer;
}
/**
* Allocates and initializes a series of types at `requested_size` in `buffer`, returning the base pointer. As a result
* of accepting a pre-allocated buffer, invocation does not allocate any dynamic memory.
*
* *Note*: passing an `buffer` smaller than `requested_size` will result in safety-checked behavior.
*/
export void * operator new[](coral::usize requested_size, coral::slice<coral::u8> const & buffer) {
if (buffer.length < requested_size) coral::unreachable();
return buffer.pointer;
}
/**
* Attempts to allocate and initialize a type of `requested_size` using `allocator`.
*
* *Note*: If the returned address is a non-`nullptr`, it should be deallocated prior to program exit. This may be
* achieved through either [coral::allocator::deallocate] or implementation-specific allocator functionality.
*/
export [[nodiscard]] void * operator new(coral::usize requested_size, coral::allocator & allocator) {
return allocator.reallocate(nullptr, requested_size);
}
/**
* Attempts to allocate and initialize a series of types of `requested_size` using `allocator`.
*
* *Note*: If the returned address is a non-`nullptr`, it should be deallocated prior to program exit. This may be
* achieved through either [coral::allocator::deallocate] or implementation-specific allocator functionality.
*/
export [[nodiscard]] void * operator new[](coral::usize requested_size, coral::allocator & allocator) {
return allocator.reallocate(nullptr, requested_size);
}
/**
* If `pointer` is a non-`nullptr` value, the referenced memory will be deallocated using `allocator`. Otherwise, the
* function has no side-effects.
*
* *Note*: passing a `pointer` value that was not allocated by `allocator` will result in erroneous behavior defined by
* the [coral::allocator] implementation.
*/
export void operator delete(void * pointer, coral::allocator & allocator) {
return allocator.deallocate(pointer);
}
/**
* If `pointer` is a non-`nullptr` value, the referenced memory block will be deallocated using `allocator`. Otherwise,
* the function has no side-effects.
*
* *Note*: passing a `pointer` value that was not allocated by `allocator` will result in erroneous behavior defined by
* the [coral::allocator] implementation.
*/
export void operator delete[](void * pointer, coral::allocator & allocator) {
return allocator.deallocate(pointer);
}
// Wrapper types.
export namespace coral {
template<typename callable, typename... arguments> concept function_pointer =