Re: [Polipo-users] structure _Atom and _AtomList usage
Brought to you by:
jch
From: Juliusz C. <jc...@pp...> - 2012-02-17 11:18:36
|
> Can someone please help me to understand what is the use of _Atom and > _AtomList structures. Its not very clear to me, can't I use a > character buffer instead. A detailed explanation will be really > helpful. Sure. An atom is an interned, read-only, reference-counted string. In other words, it's just like a string, but you cannot modify an atom, you need to create a new one. Additionally, pointer equality is equivalent to structural equality on atoms -- you don't need to strcmp atoms, you just check that the AtomPtrs are equal. Atoms are used extensively in Polipo to represent HTTP headers. First, because they can be compared in constant time, ; before I modified it to use atoms, Polipo was spending 60% CPU in the HTTP parser. Second, they save memory, since the same strings usually appear in many different HTTP headers -- a typical Polipo instance stores just a few hundred atoms that are used to encode many thousands of HTTP headers. -- Juliusz |