Hi,<br><br>We are having performance problems when running python COM Scripts. The app starts it own internal scripting engine and if we use VBScript, everything is fine. If we use PythonScript, the app consumes large amounts of memory (up to 3 GB) and the crashes because it runs out of memory.
<br clear="all"><br>This is the (simplified) PythonScript:<br>=====================================<br>counter = 0<br>for AnObject in OurApp.Array():<br> counter = counter + AnObject.Value()<br>=====================================
<br><br>The corresponding VBScript:<br>=====================================<br>for each AnObject in OurApp.Array()<br>counter = counter + AnObject.Value()<br>next<br>=====================================<br><br>This is the (simplified) C++ COM Code:
<br>=====================================<br>VARIANT COurApp::Array()<br>{<br> HRESULT hr;<br><br> SAFEARRAY * pSa;<br> pSa = SafeArrayCreateVector(VT_VARIANT, 0, 100000);<br><br> LPVARIANT psadata = NULL;<br> hr = SafeArrayAccessData(pSa, (void**)&psadata);
<br> if (FAILED(hr)) {<br> SafeArrayDestroy(pSa);<br> }<br> LPDISPATCH t = GetIDispatch(FALSE);<br> for (unsigned i = 0; i < 100000; ++i) {<br> psadata[i].pdispVal = t;<br> psadata[i].vt = VT_DISPATCH;<br>
t->AddRef();<br> }<br><br> hr = SafeArrayUnaccessData(pSa);<br> if (FAILED(hr)) {<br> SafeArrayDestroy(pSa);<br> }<br><br> VARIANT rgvar;<br> VariantInit(&rgvar);<br> V_VT(&rgvar) = VT_ARRAY|VT_VARIANT;
<br> V_ARRAY(&rgvar) = pSa;<br> return rgvar;<br>}<br><br>float COurObject::Value()<br>{<br> return rand();<br>}<br>==========================================<br><br>The returned Array can in some cases be very large. For this example, VBScript uses 1,5 Megs and Python uses about 500 Megs of RAM.
<br><br>I have set breakpoint on malloc and free in the runtime library and have observed that Python calls these functions frequently, which I suspect is part of the problem.<br><br>What can we do to optimise our application / script? Any hints / pointers are much appreciated.
<br><br>Thanks.<br>-- <br>/Johan.<br>