Mail Archives: djgpp/2002/04/13/07:40:00
Hello all.
I realize this was intended as a test program, but on the assumption
that it is based on a real program, I thought I would make a few
comments/suggestions.
--- "José_L._Sánchez_Garrido" <jlsgarrido AT yahoo DOT com> wrote:
> -------------------cut here-----------------------------------
> #include <stdio.h>
> #include <stdlib.h>
>
> typedef struct {
> char af[10];
> char name[10];
You are going to allocate 2,000,000 of these structures, which will
be ~40MB (plus overhead). Unless you know that the data being placed
in .af and .name are going to use more than 5 or characters, it *might*
be worth changing these to pointers. It all depends on the data.
>
> } record;
>
> record **dt, *d;
>
> int main (void) {
>
> int count;
>
> for(count=0; count<200000L; count++){
> dt=(record **)realloc(dt, (count+1)*sizeof(record *));
> d=dt[count];
> d=(record *)calloc(10, sizeof(record));
> }
Surely this should be something like:
#define LIMIT 200000L
dt=(record **)alloc(dt, LIMIT*sizeof(record *));
for (count=0; count<LIMIT; count ++)
dt[count]=(record *)calloc(10, sizeof(record));
Also, do you really intend to allocate an array of 10 "record"s? If
yes, then shouldn't dt be "record ***dt"?
> return(0);
> }
> ------------------cut here---------------------------------------
=====
--------------
Lets Go Canes!
__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/
- Raw text -