Skip to main content
added 161 characters in body; deleted 260 characters in body
Source Link
Aiden Bell
  • 28.4k
  • 4
  • 77
  • 121

Abstractions for a reason

For local memory allocation Really, you can wrap your free() and malloc() withprogram shouldn't have this as a custom one .concern. It is an OS concern, your problem should just be efficient with what it needs and let the OS do its job. but even then

If you insist, libraries you link may/will bypass that. You could use a debugger to get better information. You can get general statistics by reading something likelook into /proc/meminfo on Linux or using a library like this one.

You could also look into, brk(), getrlimit() and setrlimit() (here are some docs) with the RLIMIT_STACK and RLIMIT_DATA values for approximations and rough-ishes.

#include <sys/resource.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> int main (int argc, char *argv[]) { struct rlimit limit; /* Get the stack limit. */ if (getrlimit(RLIMIT_STACK, &limit) != 0) { printf("getrlimit() failed with errno=%d\n", errno); exit(1); } printf("The stack soft limit is %llu\n", limit.rlim_cur); printf("The stack hard limit is %llu\n", limit.rlim_max); exit(0); } 

Modified from here also see man getrlimit on your system

If you state what and why you want to do this, someone may have a better method or way of doing what you want.

Abstractions for a reason

For local memory allocation, you can wrap your free() and malloc() with a custom one ... but even then, libraries you link may/will bypass that. You could use a debugger to get better information. You can get general statistics by reading something like /proc/meminfo on Linux or using a library like this one.

You could also look into brk(), getrlimit() and setrlimit() (here are some docs) with the RLIMIT_STACK and RLIMIT_DATA values.

#include <sys/resource.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> int main (int argc, char *argv[]) { struct rlimit limit; /* Get the stack limit. */ if (getrlimit(RLIMIT_STACK, &limit) != 0) { printf("getrlimit() failed with errno=%d\n", errno); exit(1); } printf("The stack soft limit is %llu\n", limit.rlim_cur); printf("The stack hard limit is %llu\n", limit.rlim_max); exit(0); } 

Modified from here also see man getrlimit on your system

If you state what and why you want to do this, someone may have a better method or way of doing what you want.

Abstractions for a reason Really, your program shouldn't have this as a concern. It is an OS concern, your problem should just be efficient with what it needs and let the OS do its job.

If you insist, you could look into /proc/meminfo, brk(), getrlimit() and setrlimit() (here are some docs) with the RLIMIT_STACK and RLIMIT_DATA values for approximations and rough-ishes.

#include <sys/resource.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> int main (int argc, char *argv[]) { struct rlimit limit; /* Get the stack limit. */ if (getrlimit(RLIMIT_STACK, &limit) != 0) { printf("getrlimit() failed with errno=%d\n", errno); exit(1); } printf("The stack soft limit is %llu\n", limit.rlim_cur); printf("The stack hard limit is %llu\n", limit.rlim_max); exit(0); } 

Modified from here also see man getrlimit on your system

If you state what and why you want to do this, someone may have a better method or way of doing what you want.

added 575 characters in body; added 163 characters in body; deleted 230 characters in body
Source Link
Aiden Bell
  • 28.4k
  • 4
  • 77
  • 121

Abstractions for a reason

For local memory allocation, you can wrap your free() and malloc() with a custom one ... but even then, libraries you link may/will bypass that. You could use a debugger to get better information. You can get general statistics by reading something like /proc/meminfo on Linux or using a library like this one. 

You could also look into brk(), getrlimit() and setrlimit() (here are some docs) with the RLIMIT_STACK and RLIMIT_DATA values.

#include <sys/resource.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> int main (int argc, char *argv[]) { struct rlimit limit; /* Get the stack limit. */ if (getrlimit(RLIMIT_STACK, &limit) != 0) { printf("getrlimit() failed with errno=%d\n", errno); exit(1); } printf("The stack soft limit is %llu\n", limit.rlim_cur); printf("The stack hard limit is %llu\n", limit.rlim_max); exit(0); } 

Your OS keeps this information hidden for a reason, it isn't up toModified from here also see man getrlimit on your process to manage or even care about things other than efficient memory usage in that process. The OS kernel will swap out data to disk, and other things.system

If you state what and why you want to do this, someone may have a better method or way of doing what you want.

Abstractions for a reason

For local memory allocation, you can wrap your free() and malloc() with a custom one ... but even then, libraries you link may/will bypass that. You could use a debugger to get better information. You can get general statistics by reading something like /proc/meminfo on Linux or using a library like this one. You could also look into brk(), getrlimit() and setrlimit() (here are some docs)

Your OS keeps this information hidden for a reason, it isn't up to your process to manage or even care about things other than efficient memory usage in that process. The OS kernel will swap out data to disk, and other things.

If you state what and why you want to do this, someone may have a better method or way of doing what you want.

Abstractions for a reason

For local memory allocation, you can wrap your free() and malloc() with a custom one ... but even then, libraries you link may/will bypass that. You could use a debugger to get better information. You can get general statistics by reading something like /proc/meminfo on Linux or using a library like this one. 

You could also look into brk(), getrlimit() and setrlimit() (here are some docs) with the RLIMIT_STACK and RLIMIT_DATA values.

#include <sys/resource.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> int main (int argc, char *argv[]) { struct rlimit limit; /* Get the stack limit. */ if (getrlimit(RLIMIT_STACK, &limit) != 0) { printf("getrlimit() failed with errno=%d\n", errno); exit(1); } printf("The stack soft limit is %llu\n", limit.rlim_cur); printf("The stack hard limit is %llu\n", limit.rlim_max); exit(0); } 

Modified from here also see man getrlimit on your system

If you state what and why you want to do this, someone may have a better method or way of doing what you want.

Source Link
Aiden Bell
  • 28.4k
  • 4
  • 77
  • 121

Abstractions for a reason

For local memory allocation, you can wrap your free() and malloc() with a custom one ... but even then, libraries you link may/will bypass that. You could use a debugger to get better information. You can get general statistics by reading something like /proc/meminfo on Linux or using a library like this one. You could also look into brk(), getrlimit() and setrlimit() (here are some docs)

Your OS keeps this information hidden for a reason, it isn't up to your process to manage or even care about things other than efficient memory usage in that process. The OS kernel will swap out data to disk, and other things.

If you state what and why you want to do this, someone may have a better method or way of doing what you want.