Click here to Skip to main content
15,896,063 members

Comments by Rick York (Top 200 by date)

Rick York yesterday View    
I have fought this battle for years. That is, how can I have event logging and trace messages and display them at the same time? We could never come up with a high performance method with files so we resorted to using a shared memory buffer and then writing a separate extraction process that displayed the messages and/or wrote them to files. My current implementation is VERY high performance with an average message logging time of 750 nanoseconds. The best performance I have seen writing to a console is more than ten times slower and that's only after the text buffer has been filled once. Until then, it's another ten times slower and it takes 9000 events to fill the default buffer. Writing to a file is slower than that.

That's my recommendation: implement a ring buffer in shared memory and a separate process (I call a slurper) to display and archive the data. The buffer I use has 32K slots, 256 bytes each, and occupies 8MB of memory. One nice thing about this is multiple processes can utilize the same buffer and, if you do it right, you can have multiple buffer instances.
Rick York 3-May-24 13:08pm View    
I have used the unordered_map several times and I consider it to be very, very high performance. I have a program that puts 12K file names in a map where the first few dozen characters were all the same and it read them all from the directory in less than twenty milliseconds. I can't think of a reason for needing better performance than that. I really couldn't care less how much of the CPU it uses to do that and I can't think of a good reason why that should matter.
Rick York 30-Apr-24 17:34pm View    
That works until someone enters 100 characters and then they have an unterminated string. This is why I prefer the #define (or a const int) and the declaration to be char a[MAX_BUFFER+1]={0}; The +1 leaves room for the null character and the rest of the code doesn't change. Also, initializing it adds the null every time, including when building in release mode. If sizeof is used then a -1 is needed to be safe.
Rick York 29-Apr-24 23:51pm View    
I wrote the code the way it is specifically so I could avoid setting the null character. Initializing the buffer that way means you do not have to because it's taken care of. Using the strncpy function with the appropriate size insures that the terminating null character is not touched. THAT is why the type is defined with the +1 - it simplifies the code.
Rick York 29-Apr-24 10:15am View    
I used the code presented here successfully : https://www.codeproject.com/Articles/34508/WinAES-A-C-AES-Class