I'm just starting out with Cython and I tried to replace:
cdef class TestClass:
int m_A
def __init__(self, int a):
self.m_A = a
cdef void test_method(self):
print(self.m_A)
cdef int return_test(self):
return 1
With:
cdef cppclass TestClassCpp:
int m_A
TestClass(int a):
m_A = a
void TestMethod():
print(m_A)
int ReturnTest():
return 1
To test, I created a Main function that is called by a script I built to automatically compile the code.
cpdef int Main(str argv):
# Declare instance of Cython class and run tests
print("Python")
cdef TestClass t = TestClass(1)
t.test_method()
print(t.return_test())
# Declare instance of cppclass and run tests
print("C++")
cdef TestClassCpp* tc = new TestClass(1)
tc.TestMethod()
print(tc.ReturnTest())
return 0
I think there is some kinda memory issue. I am able to create an instance of the C++ class, and ReturnTest() works, but whenever I print m_A it prints out a random number, not the one that should be in m_A. This leads me to believe the problems could be either in the constructor or in accessing member variables from other methods. I'm doing this in an effort to optimize everything I can. So I though cppclass could be faster than class, but I've got no evidnce of this.