Thu, Oct 06 2005

Code Snippet Released - Thread-safe Singleton (for Windows platforms)

Here is an implementation of a thread-safe* C++ singleton template. It's small, simple, and easy to use.

You can download the code snippet from here: Singleton.zip

* Only construction of the class instance created by the singleton is made thread-safe. Using members of the class are not specifically made thread-safe, and remains the programmers responsibility if necessary.

posted at: 21:00 | path: /Programming/OPB/Snippets | Permanent link to this entry | Add/View comments (1 existing)

 

Wed, Jul 13 2005

Code Snippet Released - MultiStrFind

Recently I came across a situation where I needed to search for the first occurrence of any one of a number of sub-strings inside a rather large string. Using strstr would have been quite inefficient because the string would have been searched from it's beginning for each sub-string until one was found. Hence I wrote MultiStrFind. This is a C++ function* that takes the string to be searched and an array of sub-strings to search for within the string as parameters. A pointer to the first occurrence of any one of the sub-strings will be returned.

Some improvements can still be made. For instance, I'm considering performing a binary search through the sub-string array instead of looping through the sub-string array once a character has been found that is the first character of any sub-string.

You can download the code snippet from here: MultiStrFind.zip

* And probably C too, but come to think of it I haven't tried to compile it with a C compiler.

posted at: 06:03 | path: /Programming/OPB/Snippets | Permanent link to this entry | Add/View comments (0 existing)

 








Copyright ©2004-2009 O. Patrick Barnes. All rights reserved.  

Validate XHTML Validate CSS Validate RSS Green Web Hosting! This site hosted by DreamHost.