I wrote this program, where in one part, a thread takes char* buffers and write them to a pipe
that was created as follows:
ret_val = mkfifo(lpipename.c_str(), 0666);
pipehandler = open(lpipename.c_str(), O_RDWR);
then I write to the pipe one buffer after another as follows:
int size = string(pcstr->buff).length()
numWritten = write(pipehandler, pcstr->buff, size);
each pcstr->buff is a pointer to a malloc’ed size of a pre-configured size of 1-5 MB
however, it takes too long to write to the pipe , than it does to fill the pcstr->buff (from another source) and it for makes my program run too slow.
Does anyone have any idea of a faster writing method?
Thanks
Just save the length somewhere. Copying it into
std::stringjust to find out its size is rather wasteful. Or usestrlen().In Linux the default maximum pipe buffer size is 1Mb as of today. You mentioned you write more than 1Mb into the pipe. When that happens the writing thread blocks till some data from the pipe have been consumed.
Use a plain file in
/dev/shmor/tmp. On latest Linux’es/tmpis an in-memory filesystem. This only works though, if the amount of data sent through the pipe can be saved in a file without overflowing the amount of free disk space or memory.