Hello,
I'm trying to write an application that uses named pipes to transmit messages from one thread to another, but I'm running into performance issues on the platform I'm using. Here's what I have so far:
The initialization thread creates the pipes and registers them with the OS.
The thread that needs to send a message knows the name of the pipe, but doesn't have a pointer to the pipe.
The OS provides a function call to return the pointer to the pipe, but it takes 1.2ms on average to look this up, (largely due to my application having around 80 pipes and the OS has to do string compares to find the pipe) and that is prohibitively long for my application.
I dug into the OS source code, and it's using a doubly linked list to keep track of all the registered pipes. When you look up a pipe by name, it starts at the head and does a string compare on the name you pass in to what's in the pipe control block. If it matches, it returns a pointer to the pipe. If it doesn't match, it follows the next pointer and tries again until you find the correct pipe.
I was thinking about creating a new module in the OS that holds an array of structs; each struct holding the name of a pipe and the pointer to the pipe. The OS would keep the array ordered such that the names are alphabetical and then I could write an accessor function that does a binary search on the names, one char at a time until the correct pointer was found. But If I do this, I'm not sure I'll realize much of a speedup since I'm still basically doing a string compare.
I also was thinking that maybe I should use some kind of integer handle to the pipes, but I'm not sure what this would look like because there's no way for the application to know the pipe's handle unless he did some kind of lookup with the name of the pipe.
Performance is top priority in this problem as this is an embedded application. Any suggestions?
I'm trying to write an application that uses named pipes to transmit messages from one thread to another, but I'm running into performance issues on the platform I'm using. Here's what I have so far:
The initialization thread creates the pipes and registers them with the OS.
The thread that needs to send a message knows the name of the pipe, but doesn't have a pointer to the pipe.
The OS provides a function call to return the pointer to the pipe, but it takes 1.2ms on average to look this up, (largely due to my application having around 80 pipes and the OS has to do string compares to find the pipe) and that is prohibitively long for my application.
I dug into the OS source code, and it's using a doubly linked list to keep track of all the registered pipes. When you look up a pipe by name, it starts at the head and does a string compare on the name you pass in to what's in the pipe control block. If it matches, it returns a pointer to the pipe. If it doesn't match, it follows the next pointer and tries again until you find the correct pipe.
I was thinking about creating a new module in the OS that holds an array of structs; each struct holding the name of a pipe and the pointer to the pipe. The OS would keep the array ordered such that the names are alphabetical and then I could write an accessor function that does a binary search on the names, one char at a time until the correct pointer was found. But If I do this, I'm not sure I'll realize much of a speedup since I'm still basically doing a string compare.
I also was thinking that maybe I should use some kind of integer handle to the pipes, but I'm not sure what this would look like because there's no way for the application to know the pipe's handle unless he did some kind of lookup with the name of the pipe.
Performance is top priority in this problem as this is an embedded application. Any suggestions?