Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <sys/mman.h>
- #include "alloc.h"
- /**
- * alloc.
- *
- * Allocate n bytes memory in the virtual address space.
- *
- * Example
- *
- * int* p = (int *)lalloc(sizeof(int));
- * *p = 1;
- * printf("%d\n", *p);
- * lfree(p, sizeof(int));
- *
- */
- void* lalloc(size_t bytes) {
- void* p = NULL;
- p = mmap(
- 0,
- bytes,
- PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
- -1,
- 0
- );
- return p;
- }
- void lfree(void* p, size_t bytes) {
- munmap(p, bytes);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement