arrays and structures in C

Chris Torek chris at mimsy.UUCP
Sat Apr 16 02:30:10 AEST 1988


In article <12983 at brl-adm.ARPA> jfjr at mitre-bedford.arpa (Freedman) writes:
> Suppose I have some (rather large) type and I want to
>dynamically allocate a (rather large) array of said type.
>
>malloc(some_large_integer*(sizeof(rather_large_type))).
>
>But given some well known architectures this ties the
>compiler hands - it must allocate contiguous storage.

All arrays are contiguous in C, by definition.  As long as you are
going to allocate a large array, it is going to take a big chunk of
contiguous memory.

>[or] typedef rather_large_type large_array[some_large_integer];
>
>but I haven't had much luck with malloc(sizeof(large_array))

This should have precisely the same effect as before.

>[or] typedef struct {
>          int dummy_field;
>          large_array large;
>          } large_structure;
>
>malloc(sizeof(large_structure)) 

This should just allocate somewhat *more* space than the previous
two, and still require contiguous storage.

If you are stuck with an 80[12]?86 (egrep syntax), you will have
to use `huge model' to get arrays of >=65536 bytes.  The only
alternative is to break up the data structure so that each piece
is < 65536 bytes.

Think of the IBM PC as a bunch of very slow PDP-11s sharing memory. :-)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list