[GLLUG] Software Library Release

Thomas Hruska thruska at cubiclesoft.com
Mon Feb 12 14:00:38 EST 2007


Clay Dowling wrote:
> I know we don't have a lot of programmers  on the list, but some of you 
> are and you might find it useful. I had to spend some time updating a 
> library I've been using for my own projects, and I found that it was 
> polished enough for general release.
> 
> http://www.lazarusid.com/download/configlib.zip
> 
> The library provides a simple interface to key = value type config 
> files, including handling things like comments and quoted strings.  The 
> library is for C and C++.
> 
> Clay

Interesting.  Aren't there open source/public domain libraries that do 
this sort of thing already?

BTW, you are making several unsafe/odd design choices.  Hardcoding 
limits is a "bad idea".  I don't trust nor use ...scanf() functions - 
scanf() has way too many weaknesses.  You mix file I/O, custom-built 
linked lists (hard to avoid in C), and configuration logic in the same 
code set.  You use calloc() instead of malloc() (why?).  Your structure 
that you allocate is huge for the amount of data that is likely to be 
present, probably close to 90% of allocated memory is wasted.  Finding 
an entry requires scanning the linked list linearly, resulting in O(N^2) 
load times (i.e. the bigger the config, the longer it takes to load). 
Consider using a hash instead.

Also, consider why you are copying memory instead of just pointing at 
it.  Config files are generally small enough to reside entirely in 
memory and you are wasting more memory than you need to anyway. 
Consider loading the whole file in at one time and then just set a 
couple pointers and size indicators at each spot in the file that 
represents a name/value pair.  Much more efficient use of memory and 
will significantly improve loading performance.

The library is okay if the configuration files are small and no one is 
going to attempt to break any program it is used in.  Someone might find 
it useful.  I have no need for it though.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* VerifyMyPC 2.0
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.

Free for personal use, $10 otherwise.
http://www.CubicleSoft.com/VerifyMyPC/



More information about the linux-user mailing list