« Return to Thread: change SWIG c++ aligned class into c# struct during SWIG?

change SWIG c++ aligned class into c# struct during SWIG?

by Bourke Floyd :: Rate this Message:

| View in Thread

I want to change the output of my SWIG of the class btVector3 to a struct btVector3. The main issue I'm having is that I'm using BulletPhysics and I need a few core components to use structs as normal to prevent cache trashing.

"btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-byte alignment when btVector3 is stored in containers."

************************** C++ aligned class ************************
__declspec(align(16)) class btVector3
{
public:
union {
__m128 mVec128;
btScalar m_floats[4];
};
//...
}

************************** c# Wrapper OUTPUT ************************

public class btVector3 : IDisposable {
  private HandleRef swigCPtr;
  protected bool swigCMemOwn;

  internal btVector3(IntPtr cPtr, bool cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = new HandleRef(this, cPtr);
  }

  internal static HandleRef getCPtr(btVector3 obj) {
    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  }

  ~btVector3() {
    Dispose();
  }

  public virtual void Dispose() {
    lock(this) {
      if (swigCPtr.Handle != IntPtr.Zero) {
        if (swigCMemOwn) {
          swigCMemOwn = false;
          BulletPhysicsPINVOKE.delete_btVector3(swigCPtr);
        }
        swigCPtr = new HandleRef(null, IntPtr.Zero);
      }
      GC.SuppressFinalize(this);
    }
  }
///...
}

************************** C# Wrapper GOAL (TARGET) ************************
[StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct btVector3 {

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
    public float[] m_floats;

}

}


C.H. Bourke Floyd IV

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: change SWIG c++ aligned class into c# struct during SWIG?