Skip to content

Instantly share code, notes, and snippets.

@oleavr
Last active February 12, 2024 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save oleavr/a3d9d7322d5f2a1ad82c to your computer and use it in GitHub Desktop.
Save oleavr/a3d9d7322d5f2a1ad82c to your computer and use it in GitHub Desktop.
How to probe the total amount of physical memory on QNX
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/syspage.h>
int
main(int argc, char *argv[])
{
struct asinfo_entry *entries = SYSPAGE_ENTRY(asinfo);
size_t count = SYSPAGE_ENTRY_SIZE(asinfo) / sizeof(struct asinfo_entry);
char *strings = SYSPAGE_ENTRY(strings)->data;
uint64_t total = 0;
size_t i;
for (i = 0; i < count; i++) {
struct asinfo_entry *entry = &entries[i];
if (strcmp(strings + entry->name, "ram") == 0) {
total += entry->end - entry->start + 1;
}
}
printf("Total: %llu\n", total);
return 0;
}
@sanket58pawar
Copy link

Hi oleavr, does this prints the total amount of physical memory on QNX in KB or just Bytes? Please confirm

@luuhuuquyet
Copy link

it is in bits. if you want to show in KB, you have to do printf("Total: %llu\n", total/(1024*8)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment