You can use tmpfs. Use it like a normal hard drive with the path "/dev/shm"
By default it's about half the size of the system's memory (you can check it's actual size by running
df -h /dev/shm
Copy a file to the ram space
system("cp /home/pi/myfile.txt /dev/shm/my_file.txt");
