[lug] C questions.

Jason A. Crosswhite jason at newberry.uoregon.edu
Tue Nov 16 13:15:02 MST 1999


Hello all,

I'll keep it brief.  I'm writing some C code, and I have a couple
questions.  I'm using egcs 1.1.2.

1) I once found, but now lost, a web page containing the documentation
for all the gcc/egcs functions.  Anybody have a good reference site or
book they love?  Already have K&R, was wanting something a bit more
modern, advanced, and comprehensive.  I'd absolutely love a good "tips
and tricks", so to speak, of writing good C code.  Not necessarily about
the symantics of C, but the accepted good coding form and structure. 
For instance, I'm sure there's more or less common wisdom about how to
do dynamic memory allocation, or the easiest optimizations for speeding
up code if you're doing "blah".  The web page I lost seemed to have nice
discussions about how to use each function, like "You should probably
use this function most efficiently and safely using something like the
following code ....., make sure to check for a NULL return, otherwise,
....blah, blah."

2) I need to try to do some dynamic memory allocation.  I'd like to find
a brief explanation of how it should be done, or better yet some example
code somewhere?  Basically, I need to find the nonzero indeces of a
_HUGE_ (like more than millions of entries) sparse matrix.  All I'm
doing is growing a two dimensional array which will have the row and
column indices of said entries, but I have no idea how many I have until
I find them!  It seems inefficient to call realloc every time I find a
new index.  I was thinking of just reallocing enough space for say 100
ints every time I find another 100 of them (or thousand, or whatever
seems to be most efficient), then I'd never be wasting more space than
for about 100 ints.  That seems rather crude to me though.  Isn't there
a better way, or is that about it?

I know this isn't exactly a linux question.  Hope I'm not too off base.

--
-Jason Crosswhite

jason at newberry.uoregon.edu
http://darkwing.uoregon.edu/~jacrossw
Rm 220, Cascade Building
University of Oregon





More information about the LUG mailing list