Profiling Memory Peaks of code execution
29 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I was using the profiler to get acess to memory peaks in my code execution.
I am now wondering how a simple indexing command of a logical array can have peaks up to 8000Kb.
The command ist actually something like:
variable(index) = true;
Here "variable" is a logical array of size 241, so actually 241 bits (I know this has to be multiplied by 8 because Matlab stores each bit in one byte because of performance), and index is int16 between 1 and 241. And in the Code I change the value of the variable to true or false, depending on a condition.
Nevertheless this line has peaks up to 8000 Kb.
How does this come?
EDIT:
Ok, somehow the number of calls plays a role... around 100000 at the moment.
How to get the allocation memory of the single execution?
Holly ... how can I change the unit from Kb to byte or to expand the format to long or something like this?
Thanks
2 comentarios
Respuestas (1)
Ashutosh Thakur
el 24 de En. de 2024
Editada: Ashutosh Thakur
el 24 de En. de 2024
Hi Roman,
The MATLAB profiler provides a way to measure time which is spent on executing each line of code, but to measure the memory usage memory function can be used to analyze the memory usage of each line of code.Following documentation link can be reffered for more information regarding the memory function: https://www.mathworks.com/help/matlab/ref/memory.html
The following code example shows the way in which memory usage can be measured for the particular line of code:
[userview_1, ~] = memory;
variable(index) = true;
[userview_2, ~] = memory;
memory_difference = userview_2.MemUsedMATLAB - userview_2.MemUsedMATLAB;
The memory_difference variable will provide you with the value of the memory which is used by the particular line of code.
In order to resolve the memory usage issues, kindly follow the strategies mentioned below:
- Try to use appropriate data structure for the variables, classes depending on their usage so that less memory is used.
- Try to use the Sparse matrix as much as possible.
- Prevent creating the temporary copies of an array, try to pre-allocate and use repmat function as much as possible.The usage of repmat can be understand through the following documentation link: https://www.mathworks.com/help/matlab/ref/repmat.html
Please refer to the following documentation links regarding optimizing the memory usage in MATLAB:
- https://www.mathworks.com/help/matlab/matlab_prog/strategies-for-efficient-use-of-memory.html
- https://www.mathworks.com/help/matlab/matlab_prog/memory-allocation.html
- https://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html
I hope the above information helps you in measuring the memory usage.
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!