Questions tagged [mmap]

mmap is a POSIX-compliant Unix system call that maps files or devices into memory.

mmap() creates a new mapping in the virtual address space of the calling process.

https://en.wikipedia.org/wiki/Mmap

1936 questions
0
votes
1 answer

Identify flag in mmap function

void *mmap(void *addr, size_t length, int prot, int flags,int fd, off_t offset); I see call to mmap that prot=3 and flags=1 what does it mean about this buffer? ,How can I translate the flag that I see in man to number? Is the user can read/write…
parser1234
  • 111
  • 1
  • 7
0
votes
1 answer

Memory Mapping An Array to Another Array In C

I'm working with a loop with a very high iteration count, and so code within it will be quite performance critical. At some point in the loop I take a previously populated array of doubles and pass it to a function that for our purposes we can…
muke
  • 306
  • 2
  • 11
0
votes
1 answer

C mmap implementation for linux command

I have the following code which basically reproduce the functionality of the wc command in linux. My question is how I can rewrite the code using mmap? I know I can use struct stat sb; and then char *file_in_memory = mmap(NULL, sb.st_size,…
gameloverr2
  • 85
  • 2
  • 17
0
votes
0 answers

Extending a memory-mapped file in Python (Mac & Linux)

On Windows mmap'd files can be automatically extended on open, but this is not supported on UNIX-like systems: https://docs.python.org/3.7/library/mmap.html I have an existing set of classes that provide an append-only journal in Python using mmap,…
0
votes
1 answer

Mmap, void pointer and type casting in C

I'm reading C on disk hash table code without knowing much about C or mmap but i know Golang. This piece of code confuses me. There are two structs like this. typedef struct HashTbl { void *data; ... } HashTbl; typedef struct Header { …
TomSawyer
  • 3,711
  • 6
  • 44
  • 79
0
votes
2 answers

Insert image in blob in Sqlite

I am reading a directory for 600,000 images and wanting to store these images in a Sqlite DB. The DB structure is simply ID, IMAGE (blob). I'm not proficient in C++ so am figuring this out. First I open the DB file and setup the prepare statement…
Mudders
  • 127
  • 2
  • 12
0
votes
1 answer

shm_open segmentation fault and permission failed

I am new to Linux and i am trying to create a shared memory object which stores the collatz conjecture calculated in child process and prints it in parent process. I have already read the man pages for the commands. When I create the object it…
Shary
  • 101
  • 1
  • 9
0
votes
1 answer

How can we mmap a datastructure in python?

I have huge dictonary with some contents in memory which was created by searching similary sentence in a big wikipedia corpus . It has below dictonary format ,when i writed into a file its size was 150mb ,Now before writing it to file i want to…
star
  • 244
  • 1
  • 2
  • 10
0
votes
1 answer

How to write into shared memory from a child process

I'm experimenting with child processes because this seems the only way to make an old C library run in parallel that cannot be used in threads. My minimal example writes three integer values into mapped memory. In the child process, I want to change…
gk017
  • 87
  • 1
  • 10
0
votes
1 answer

Create a new file to write to in C and initialize it as empty?

I want to open a new file and write a char array to it, but when I read back the contents of the file it has what I wrote to it followed by a bunch of garbage characters. I want to map the file to memory, but when I read the file back from that map,…
thebaconator
  • 223
  • 6
  • 10
0
votes
1 answer

Mmap problem -> segfault

I would like to share to use mmap. However it doesn't work, because I'm getting a segfault : int fdL = open("/dev/zero", O_RDWR | O_CREAT); int *ligneC = (int *) mmap(0, sizeof (int), PROT_READ | PROT_WRITE, MAP_SHARED, fdL, 0); *ligneC = 0; Where…
g123k
  • 3,748
  • 6
  • 42
  • 45
0
votes
1 answer

mmap() causing segmentation fault in C

I'm pretty sure my mistake is very evident, but I just can't seem to find where the problem is. I'm learning how to use mmap() in C, everything looks correct to me, but I get a segmentation fault. Here is my code: int n=50; char * tab = mmap(NULL,…
CSstudZ
  • 101
  • 10
0
votes
0 answers

Assembly sys_mmap linux x64 Bus failure

i opened a file (MEMORY) then i tried to use mmap syscall but after mmap called, i tried to use the allocated space and i got (Bus error) in Linux what is the problem !? i think something is wrong with my mmap parameters FORMAT ELF64…
ELHASKSERVERS
  • 195
  • 1
  • 10
0
votes
1 answer

Is it safe to modify file in place when replacement is same size as original

I want to do something similar to sed -i 's/abc/def/' file but without temp file. In my case match and replacement are of same length; is the following safe: fd = open(file, O_RDWR); fstat(fd, &sbuf); mm = mmap(0, sbuf.st_size, PROT_READ |…
Ani
  • 1,448
  • 1
  • 16
  • 38
0
votes
1 answer

Is there a faster way to check if a txt file has two strings in it?

I am developing a script to read through logs on a log folder and check on each .txt log file: 1) if the log has the string 'FileData' and 2) if the log does not have the string 'Error in File Data' If this condition is met, it needs to read the…
1 2 3
99
100