Skip to content

Commit

Permalink
virt mem max
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarzhavoronkov committed Mar 31, 2016
1 parent fa6af24 commit 3ad6d27
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tasks/virt_mem_max/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
#include<sys/mman.h>
#include<stdio.h>

int main()
{
// TODO
return 0;

size_t bytes_to_allocate = 1;
void* res = NULL;
while (res != MAP_FAILED)
{
void* addr = mmap(NULL, bytes_to_allocate, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
bytes_to_allocate *= 2;
res = addr;
}

size_t bytes_to_allocate1 = bytes_to_allocate / 2;
while (res != MAP_FAILED)
{
void* addr = mmap(NULL, bytes_to_allocate1, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
bytes_to_allocate1 /= 2;
res = addr;
}

printf("Allocated: %zu bytes of memory\n", bytes_to_allocate + bytes_to_allocate1);
return 0;
}
Binary file added tasks/virt_mem_max/virt_mem_max
Binary file not shown.

0 comments on commit 3ad6d27

Please sign in to comment.