Hi ALL,
i really need some help with the following task.
Can anyone tell me how to write a program that determines the maximum amount of continuous memory that you can allocate from the C runtime heap on your local system.
So far i have this:
Code:#include <stdlib.h> #include <stdio.h> #include <math.h> int main () { int i; long size = powl(2, 30); long result = -1; for (i = 29; i >= 0; i--) { size += powl(2, i); printf("try %ld ", size); char *p; if (p = malloc(size)) { result = size; printf("ok\n"); *(p + size - 1) = 'a'; free(p); } else { size -= powl(2, i); printf("not ok\n"); } } printf("result %ld\n", result); }
but im not sure if the memory allocated here is all continuous.
Thank you in advance,
Prespa