Merge pull request #17482 from markdroth/remove_memory_alignment_hack

Revert alignment hack in New<> and Delete<>.
pull/17487/head
Mark D. Roth 6 years ago committed by GitHub
commit 5e492721de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/core/lib/gprpp/memory.h

@ -40,15 +40,10 @@
namespace grpc_core { namespace grpc_core {
// The alignment of memory returned by gpr_malloc().
constexpr size_t kAlignmentForDefaultAllocationInBytes = 8;
// Alternative to new, since we cannot use it (for fear of libstdc++) // Alternative to new, since we cannot use it (for fear of libstdc++)
template <typename T, typename... Args> template <typename T, typename... Args>
inline T* New(Args&&... args) { inline T* New(Args&&... args) {
void* p = alignof(T) > kAlignmentForDefaultAllocationInBytes void* p = gpr_malloc(sizeof(T));
? gpr_malloc_aligned(sizeof(T), alignof(T))
: gpr_malloc(sizeof(T));
return new (p) T(std::forward<Args>(args)...); return new (p) T(std::forward<Args>(args)...);
} }
@ -57,11 +52,7 @@ template <typename T>
inline void Delete(T* p) { inline void Delete(T* p) {
if (p == nullptr) return; if (p == nullptr) return;
p->~T(); p->~T();
if (alignof(T) > kAlignmentForDefaultAllocationInBytes) { gpr_free(p);
gpr_free_aligned(p);
} else {
gpr_free(p);
}
} }
template <typename T> template <typename T>

Loading…
Cancel
Save