Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform: add totalRAM. #1840

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

saurtron
Copy link
Collaborator

@saurtron saurtron commented Dec 20, 2024

Work done

  • Add Platform.totalRAM to get total system ram as a number in MB.

Related issues

  • Fixes Add Platform.AvailableRAM #1640
    • not the same name but imo AvailableRAM or FreeRAM should be reserved for smth else reporting actual free ram, that seems a bit trickier tho and possibly not so useful because the number could be misleading, so for now just adding TotalRAM.

Remarks

  • I see games having to parse the hardware string, that seems awkward and fragile.
  • Not sure if I'm using the best approach here, _SC_PHYS_PAGES is not POSIX standard, but I hope it won't be a problem. It does seem to be supported in freebsd as well as linux.

@sprunk
Copy link
Collaborator

sprunk commented Dec 20, 2024

Fixes #1640

@saurtron saurtron added area: Lua API status: candidate PRs that should be good to go or important for next release labels Dec 20, 2024
@sprunk
Copy link
Collaborator

sprunk commented Dec 28, 2024

  • would be nice to avoid #ifdef _WIN32 and to instead put code in /rts/System/Platform/Win/*.cpp.
  • there is already some code that gets total RAM, would be good to avoid duplicate code. Figure out if there are behaviour differences and document them, otherwise if the behaviour is the same refactor the existing code so the same source of truth is used both for infolog.txt printing and for the new Lua var:
    if (memInfo != nullptr) {
    while (fgets(buf, sizeof(buf), memInfo) != nullptr) {
    if (strstr(buf, "MemTotal") != nullptr) {

    MEMORYSTATUSEX statex;
    constexpr int div = 1024 * 1024;
    statex.dwLength = sizeof(statex);
    GlobalMemoryStatusEx(&statex);

@saurtron
Copy link
Collaborator Author

saurtron commented Jan 2, 2025

  • would be nice to avoid #ifdef _WIN32 and to instead put code in /rts/System/Platform/Win/*.cpp.
  • there is already some code that gets total RAM, would be good to avoid duplicate code. Figure out if there are behaviour differences and document them, otherwise if the behaviour is the same refactor the existing code so the same source of truth is used both for infolog.txt printing and for the new Lua var:

Done, lemme know if there's anything else you'd like changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Lua API status: candidate PRs that should be good to go or important for next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Platform.AvailableRAM
3 participants