Skip to content

Alignment in rawMemory function in utils.h #2

Description

@yuval-khachatryan

I think there are couple of issues with
struct EMPTY{}; template<typename ITEM> ITEM* rawMemory(int n = 1) {return (ITEM*)::operator new(sizeof(ITEM) * n);}

  1. I think aligned new should be used - the correct version doesn't take alignment of Item into consideration. Correct me if I am wrong.
  2. Not sure - but I think that attempting to use the returned pointer is UB for pretty much everything, including pointer arithmetic. (Not 100% sure, may be this case is covered by implicit-lifetime in C++20 standard), even though it should work in practice on all compilers, as far as I know.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions