2 * Memory allocation with mmap()
4 * Luiz Fernando N. Capitulino
5 * <lcapitulino@gmail.com>
14 #define DEFAULT_SIZE 10 /* will be 10k */
16 static void print(const char *msg
, ...)
22 va_start(params
, msg
);
23 vfprintf(stderr
, msg
, params
);
29 int main(int argc
, char *argv
[])
36 bytes
= (size_t) strtol(argv
[1], NULL
, 10);
40 print("Will allocate %d kBytes", bytes
/ 1024);
42 p
= mmap(NULL
, bytes
, PROT_READ
| PROT_WRITE
,
43 MAP_PRIVATE
| MAP_ANONYMOUS
, -1, 0);
44 if (p
== MAP_FAILED
) {
51 print("Allocated %d kBytes", bytes
/ 1024);
55 print("Memory is now freed");