Page MenuHomeFreeBSD
Authored By
dougm
May 18 2019, 7:43 AM
Size
588 B
Referenced Files
None
Subscribers
None

mapper.c

#include <sys/mman.h>
#include <stdlib.h>
#include <stdio.h>
enum {MAX_MAPS = 16384, MAP_SIZE = 4096 };
void *mappings[MAX_MAPS];
int main()
{
int i;
int nmappings = 0;
for (i = 0; i < 128 * MAX_MAPS; ++i) {
long r = random() % MAX_MAPS;
if (mappings[r] == NULL) {
mappings[r] = mmap(0, MAP_SIZE, PROT_WRITE, MAP_ALIGNED(13) | MAP_ANON, -1, 0);
if (mappings[r] != NULL)
++nmappings;
} else {
munmap(mappings[r], MAP_SIZE);
mappings[r] = 0;
--nmappings;
}
}
printf("nmappings = %d; ok?\n", nmappings);
getchar();
return 0;
}

File Metadata

Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1898428
Default Alt Text
mapper.c (588 B)

Event Timeline