Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Question regarding MathLink memory use
Posted:
Aug 22, 2012 2:25 AM


Hi,
I have a question about memory usage when using MathLink and C++. Here is my setup:
(1) A dynamic user interface in Mathematica which displays positions of points (the points are stored in a list). (2) A C++ function that updates the position of the points. (3) The dynamic user interface calls the C++ function with a list of current point positions and the C++ function returns a list of updated positions.
The C++ function has no memory leaks (the process size remains constant throughout the simulation); however, the Mathematica process (Windows 7) memory usage keeps growing as the simulation runs. Here is the code which returns the C++ computation to Mathematica via MathLink.
if (MLPutFunction(stdlink,"List" ,3)) { if (!MLPutReal64Array(stdlink, pointTotalForces, dims, NULL, 2)) { /* Handle error ...*/ } else if (!MLPutReal64(stdlink, Sim.meanPointForceMagnitude)) { /* Handle error ...*/ } else if (!MLPutReal64(stdlink, Sim.maxPointForceMagnitude )){ /* Handle error ...*/ } } else { /* Handle error ... */ }
The result is stored in a List in Mathematica, i.e., result = Simulate[....]. The points' positions then dynamically updated in a visualization. I am using Mathematica version 8.0.4 in Windows 7 and the MathLink code is a 64bit executable built with Visual Studio 2010.
I would appreciate any suggestions.
Sam



