Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a Global Atom from a partial string

Tags:

winapi

I can create an Global Atom using GlobalAddAtom and I can find that atom again using GlobalFindAtom if I already know the string associated with the atom. But is there a way to find all atoms whose associated string matches a given partial string?

For example, let's say I have an atom whose string is "Hello, World!" How can I later find that atom by searching for just "Hello"?

like image 316
Andrew Lambert Avatar asked Feb 24 '23 10:02

Andrew Lambert


1 Answers

Unfortunately, the behavior you're describing is not possible for Atom Tables. This is because Atom Tables in Windows are basically Hash Tables, and the mapping process handles strings in entirety and not by parts.

Of course, it almost sounds like it would be possible, as quoted from the MSDN documentation:

Applications can also use local atom tables to save time when searching for a particular string. To perform a search, an application need only place the search string in the atom table and compare the resulting atom with the atoms in the relevant structures. Comparing atoms is typically faster than comparing strings.

However, they are referring to exact matches. This limitation probably seems dated compared to what is possible with resources currently available to software. However, Atoms have been available as far back as Win16 and in those times, this facility allowed a means for applications to manage string data effectively in minimal memory. Atoms are still used now to manage window class names, and still provide decent benefits in reducing the footprint of multiple stored copies of strings.

If you need to store string data efficiently and to be able to scan by partial starting matches, a Suffix Tree is likely to meet or exceed your needs.

like image 182
meklarian Avatar answered Jun 07 '23 11:06

meklarian