Mail Archives: djgpp-workers/1997/11/11/05:30:35
On Mon, 10 Nov 1997, Charles Sandmann wrote:
> > > pathalogical data initialization codes to see how they perform in
> > What are these, please?
>
> There were some examples discussed on the NG/Mailing list about a month
> back, in which the initialization of an array with a large number of
> elements consumed a huge amount of memory. I would suggest checking the
> mailing list archives - I don't remember the details.
Here's a source that reveals this problem.
Please note that this source causes a lot of allocations, but I'm not
sure it also causes a lot of calls to realloc/free.
Also note that the actual source is 300K and I didn't want to post it
in its entirety. You will have to replicate the lines that initialize
the array with your favorite editor or another tool.
#include <stdio.h>
#include <stdlib.h>
unsigned xxx[100000] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
/* there should be 10,000 lines like this */
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
};
int main (void)
{
return printf ("%d\n", xxx[rand() % 3] + xxx[rand() % 4]);
}
- Raw text -