Reputation: 635
I have a void *buffer
that is an instance of a file in RAM.
The file type is in a format that must be parsed by the API given.
Unfortunately, the only way to open this file type through the API is to supply the API with the file path:
sample_api_open(char *file_name, ...);
I understand that shm_open
returns the file descriptor, but the API only takes a file path.
Is there a work around to read this type of file in memory?
Upvotes: 1
Views: 2243
Reputation: 17420
Is there a work around to read this type of file in memory?
Dump the content of the buffer into a temporary file on /tmp
.
On the vast majority of modern *NIX systems, the /tmp
is a synthetic, in-memory file system. Only in case of the memory shortage, the content might hit the disk due to the swapping.
If the amount of the information is too large, to avoid duplication, after dumping the content onto /tmp
, you can free the local memory and mmap()
the content of the file.
Upvotes: 1
Reputation: 92984
Instead of using POSIX shared memory, you could open a temporary file and mmap()
it. Then make the buffer end up in the mmap()
-ed region so you can finally call the API on the temporary file.
Upvotes: 0