“I always say, 'This will be my last 'Metal Gear.'” Hideo Kojima

Using EASTL in your projects

As many of you may know, EA open-sourced days ago its very own STL implementation called EASTL. It’s been out there for a while (partially) but now its fully available…and that’s GOOD news.

EASTL has (supposedly) better performance than standard STL and is designed with consoles in mind. Better performance is always welcome. So does a console-aware design because important hardware restrictions come into play (e.g: less memory), and a more generic library will likely fail to do the job. Perfect for a game engine. And who’s developing one? (Me)

What if you want to use EASTL in your projects? Easy.

UPDATE: Forgot to add EABase on Method 1.
UPDATE 19/2/2016: If you pull last EASTL versions, there's no need to add EABase anymore because EASTL does it for you. Also added info about operators and updated methods.

Step 1. Using Cmake

  1. Clone EA’s repo and copy it into your project
git clone https://github.com/electronicarts/EASTL.git
  1. Simply add the EASTL and EABase folders to your project root’s CMakeLists.txt.

    add_subdirectory(EASTL/test/packages/EABase)
    add_subdirectory(EASTL)

  2. EASTL will compile as an .a library so you can link it with target_link_libraries()

  3. Finally, as @maxburke appointed on Gitter (and also as you can read on allocator.h source file), since we are linking it as a regular library, EASTL expects us to implement this two operators for ourselves:

void* operator new[](size_t size, const char* pName, int flags, unsigned debugFlags,
		const char* file, int line);

void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, const char* pName,
		int flags, unsigned debugFlags, const char* file, int line);  	

Citing @maxburke again, this is done so because “EASTL requires that you provide an overloaded operator new, the presumption here is that you can add all the tracking and debug information injection that you can’t normally get”. You can just implement them like this:

void* operator new[](size_t size, const char* pName, int flags, unsigned debugFlags, const char* file, int line) 
{
  return malloc(size);
}  

void* operator new[](size_t size, size_t alignment, size_t alignmentOffset, const char* pName, int flags, unsigned debugFlags, const char* file, int line) 
{
  return malloc(size);
}  

Step 2. Including headers

1. Clone EA’s repo
2. Find EABase library under EASTL/test/packages/EABase/
3. Copy (or link) EABase/include/Common/EABase and EASTL/include/EASTL folders to your include directory>/del>

  1. Copy (or link) EASTL/include/EASTL folder to your include directory
  2. That’s it! You can now include like this:
#include <EASTL/unique_ptr.h>  
#include <EASTL/algorithm.h>

Happy coding!

Jordi