Coder Social home page Coder Social logo

Comments (6)

skypjack avatar skypjack commented on May 20, 2024

Have you tried it already in your project? Can you confirm that it works as expected?

from entt.

jdumas avatar jdumas commented on May 20, 2024

Yes! But if there are other places where EnTT is using a placement new, those may also need to be updated. Happy to work on a MWE without Jolt if you think that's useful.

from entt.

skypjack avatar skypjack commented on May 20, 2024

The only other class that uses placement new is any afaik.
I don't think a MWE with Jolt is required here actually. A standalone test that doesn't use external libraries would be way better to avoid future regression probably.
Do you have bandwidth to pack something in this sense for the utility in memory.hpp? A rough example would be enough, I can then fix it and throw it in myself but it would definitely save me a lot of time!

from entt.

jdumas avatar jdumas commented on May 20, 2024

Sure. As I said I was planning to provide a MWE without Jolt. So here it is:

#include <entt/entt.hpp>

#include <stdlib.h>
#include <cstdlib>

namespace MyLib {

void* Allocate(size_t inSize)
{
    return malloc(inSize);
}

void Free(void* inBlock)
{
    free(inBlock);
}

void* AlignedAllocate(size_t inSize, size_t inAlignment)
{
#if defined(_WIN32)
    return _aligned_malloc(inSize, inAlignment);
#else
    void* block = nullptr;
    posix_memalign(&block, inAlignment, inSize);
    return block;
#endif
}

void AlignedFree(void* inBlock)
{
#if defined(_WIN32)
    _aligned_free(inBlock);
#else
    free(inBlock);
#endif
}

class Foo
{
public:
    Foo(int x_)
        : x(x_)
    {}

public:
    void* operator new(size_t inCount) { return MyLib::Allocate(inCount); }
    void operator delete(void* inPointer) noexcept { MyLib::Free(inPointer); }
    void* operator new[](size_t inCount) { return MyLib::Allocate(inCount); }
    void operator delete[](void* inPointer) noexcept { MyLib::Free(inPointer); }
    void* operator new(size_t inCount, std::align_val_t inAlignment)
    {
        return MyLib::AlignedAllocate(inCount, static_cast<size_t>(inAlignment));
    }
    void operator delete(void* inPointer, [[maybe_unused]] std::align_val_t inAlignment) noexcept
    {
        MyLib::AlignedFree(inPointer);
    }
    void* operator new[](size_t inCount, std::align_val_t inAlignment)
    {
        return MyLib::AlignedAllocate(inCount, static_cast<size_t>(inAlignment));
    }
    void operator delete[](void* inPointer, [[maybe_unused]] std::align_val_t inAlignment) noexcept
    {
        MyLib::AlignedFree(inPointer);
    }

protected:
    int x;
};

} // namespace MyLib

int main(void)
{
    entt::registry r;
    auto e = r.create();
    r.emplace<MyLib::Foo>(e, 42); // <-- doesn't compile
    return 0;
}

from entt.

skypjack avatar skypjack commented on May 20, 2024

As I said I was planning to provide a MWE without Jolt

You're right and I read it wrong. 😅
Thanks for the example, I'll use it as the basis for a non-regression test. 👍

from entt.

jdumas avatar jdumas commented on May 20, 2024

All good, thanks for looking into it!

from entt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.