Last active
February 21, 2021 20:01
-
-
Save iximeow/4f1db04f004131801f989259ee344c33 to your computer and use it in GitHub Desktop.
how to download more ram
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* if you need more memory, add some to your program with this cool trick | |
*/ | |
#include <errno.h> | |
#include <fcntl.h> | |
#include <inttypes.h> | |
#include <stddef.h> | |
#include <stdio.h> | |
#include <sys/mman.h> | |
int main() { | |
// have to open a partition on the disk, not the disk itself. so do one big disk-sized file? | |
int fd = open("/dev/nvme1n1", O_RDWR); | |
printf("fd: %d\n", fd); | |
void* ptr = mmap(NULL, 0x1000000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0); | |
printf("ptr: %p\n", ptr); | |
int* intptr = (int*)ptr; | |
printf("before: %x%x%x\n", intptr[0], intptr[1], intptr[2]); | |
intptr[0] = 0x12345678; | |
intptr[1] = 0xcafebabe; | |
intptr[2] = intptr[2] += 1; | |
printf("after: %x%x%x\n", intptr[0], intptr[1], intptr[2]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment