nfprojects / nfengine

Game engine
GNU General Public License v2.0
55 stars 4 forks source link

Implement custom memory allocators #103

Open Witek902 opened 9 years ago

Witek902 commented 9 years ago

Currently, all memory allocations are done via malloc/new. This is OK in some cases (unit tests), but using it for managing objects which are frequently created and deleted have flaws:

TODO checklist:

class Foo
{
    // creates memory pool allocator that allocates sizeof(Foo) blocks and
    // generates new/delete operators
    NFE_REGISTER_CLASS(Foo);
...
};

Write test cases and performance test of e.g. entities creation and deletion. Compare the performance after moving to the new allocators.

mkulagowski commented 9 years ago

Last 2 points of the First Steps pique my interest - why stop using std::string, when we provide stl allocators? Is it because of all unused features, that the std::string gives over char arrays?

Witek902 commented 9 years ago

@mkulagowski No, it's because performance. std::string uses memory allocation, which we should avoid. For example, at https://github.com/nfprojects/nfengine/blob/devel/nfEngine/nfCore/Mesh.cpp#L107 we could use simple C-string to concatenate the path (the string would be keeped on a stack). In unit tests we can use normal std::string, because we don't care performance much there.