Path: utzoo!mnetor!uunet!husc6!purdue!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: arrays and structures in C Message-ID: <11078@mimsy.UUCP> Date: 15 Apr 88 16:30:10 GMT References: <12983@brl-adm.ARPA> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 38 In article <12983@brl-adm.ARPA> jfjr@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@mimsy.umd.edu Path: uunet!mimsy!chris