I used swig in the pass and I really like it.
I already have the wrapper generated and convert almost the complete engine, but this has forced me to make some changes.
the first is that in all garbage collection languages like Python and csharps, objects memory allocations.
this is a problem because in the engine side, I decided to simply memory alignment by making it 32 bytes.
I found this a reasonably compromise for a physics library since objects are not really that small, so assuming just one alignment for every thing is fine to me.
this means if something alloc 1 byte object, it the allocation will pad it with 32 bytes.
this immediately created a problem with the wrapper, because if it make something like a vector
the wrapper does not make an instance, instead it keeps a pointer to an allocated object.
but since those object do not have memory allocators, the wrapped call the generic new and delete, but the generic new and delete does not allocate 32 bytes aligned memory chunks.
of course this can eassy be fix by adding a global operator new like this.
- Code: Select all
void *operator new (size_t size)
{
return dMemory::Malloc(size);
}
but I consider that a very hacky and cheap solution
the proper solution is to make all class derived from the dClassAlloc calls so that the yget the operator new and delete.
so that fixed that problem.
however this brings a new problem.
this changes make visual studio 2015 and lower ignore inline and __inline operator and make all the math functions call with very catastrophic performance problems.
fortunately Visual studio 2017 does not have that problem. so I guess it is time to abandone VS 2015 compatibility.
to summarized this class
- Code: Select all
class dVector : public dClassAlloc
{
#define PERMUTE_MASK(w, z, y, x) _MM_SHUFFLE (w, z, y, x)
public:
D_INLINE dVector()
{
}
}
makes dVector() a function call in vs2015
but this class below doesn't
- Code: Select all
class dVector
{
#define PERMUTE_MASK(w, z, y, x) _MM_SHUFFLE (w, z, y, x)
public:
D_INLINE dVector()
{
}
}
but with VS2017 but classes result on inline functions.
anyway I went over the code and made most classes subclasses of dClassAlloc so that the wrapper are happy with the expected alignment
now it is time to test it with the blender addon project.