Memory usage limitation for standalone Matlab app designer Apps using Matlab Compiler

16 Ansichten (letzte 30 Tage)
Hi all,
I have a simple question which need a simple answer (i hope i will not hear the can't be done answer as i am expecting it):
i am making an app in matlab App designer and then converting it to EXE file to run on client computer. the problem as as above i need somehow to dynamiclly control the memory usage of my EXE app according to available physical memory of my client. can i do this?
my goal is to simply limit the available memory to my Matlab EXE app to lets say 80% client system physical memory. is it possible?
I have already tried the Matlab Workspace in Preferences option and did not work for me. (the code is too big to change now, and that is why i dont want to change the code if possible. my bottleneck is FFT calculation on a matrix of about /this may change/ 3000000x6 which as you can see i know but i dont if possible want to change)
Thanks for the support
Best Regards

Antworten (1)

Harsh Mahalwar
Harsh Mahalwar am 19 Feb. 2024
Bearbeitet: Harsh Mahalwar am 19 Feb. 2024
Hi Aubai,
As I can understand, you are trying to limit MATLAB’s memory usage according to the available memory. Using MATLAB workspace in preference option is a possible solution but you have already tried that, and it did not work for you.
Here’s a workaround, you can also try changing the java heap size.
To adjust the heap size:
  1. On the Home tab, in the Environment section, click Preferences. Select MATLAB > General > Java Heap Memory.
  2. Select a value using the slider or spin box.
Note: Increasing the heap size decreases the amount of memory available for storing data in arrays.
3. Click OK.
4. Restart MATLAB.
But obviously, I can understand that changing Java heap size might not be a good solution in your use case as it is not possible to adjust the heap size dynamically (at least effectively, there are ways to change it with code, but they require a restart).
Another possible workaround can be to use the “memory” function with a break loop. Here’s an example:
% for this example, I am setting memory threshold as 80
thresholdMemory = 80;
while true
% You can call your entry point function here!
% This part checks memory usage.
[~, memObj] = memory;
availableMemory = memObj.PhysicalMemory.Available;
totalMemory = memObj.PhysicalMemory.Total;
memoryInUse = 100*(totalMemory-availableMemory)/totalMemory;
% break loop if memory usage exceeds the threshold.
if memoryInUse > thresholdMemory
break;
end
end
Learn more about the “memory” function using the following link:
I was also able to find a similar MATLAB Answers question, you can also try using methods suggested here,
You can also try using Operating system specific memory management methods like,
Using Windows job object, this is a bit advanced and requires programming with the Windows API. You can also leverage third party applications for the same.
(this method is not supported by MATLAB officially, so it might be more tedious to work with)
In case of linux, you can use the ulimit command in the shell to limit the resources available. “cgroups” feature can also be used. (you can checkout open-source job schedulers like “slurm workload manager”).
(this method is not supported by MATLAB officially, so it might be more tedious to work with)
I hope this helps, thanks!
  3 Kommentare
Aubai
Aubai am 20 Feb. 2024
Hi Harsh,
Thanks for the support. i am not sure about this so the memory function is providing information but where is the code line which is telling Matlab do not go higher that 80%?
I mean yes you are saying in your code
% using the max available all arrays property, we limiting the memory usage
% of matlab.
but for me it seems like a variable in the workspase which is meaningless if not some how set to a given property in Matlab envinroment, right?
Again thanls alot for your time and support
Harsh Mahalwar
Harsh Mahalwar am 20 Feb. 2024
Bearbeitet: Harsh Mahalwar am 20 Feb. 2024
Hey Aubai,
You're correct here, memory function can only be used to display information related to memory usage. I'll remove my comment.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by