Custom allocators support
One common issue when porting code to Cheerp is the lack of support for custom allocators that return void pointers.
Let’s take this code for example:
Cheerp will emit a compile time error:
The problem is that allocations in cheerp are translated to the creation of a JS object with the right set of properties. This code:
translates to the following JS code:
As you can see, the type information provided by the cast operator is needed to provide the right object layout. An equivalent (and better) solution is to use the C++
new operator whenever possible.
If for some reason you really need the custom allocator function, consider using a template: