Xref: news2.mv.net comp.os.msdos.djgpp:6781 From: C M Marka Newsgroups: comp.os.msdos.djgpp Subject: Re: Flat Memory Questions Date: Sat, 3 Aug 1996 16:22:52 +0000 Organization: LITNET Lines: 28 Message-ID: References: <720 DOT 9607281807 AT ws-ai5 DOT dur DOT ac DOT uk> NNTP-Posting-Host: santaka.sc-uni.ktu.lt Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII In-Reply-To: <720.9607281807@ws-ai5.dur.ac.uk> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp On Sun, 28 Jul 1996 Sengan DOT Short AT durham DOT ac DOT uk wrote: > > char Array[1024*1024]; > void main ( void ) > { ... } > Array is now static: ie a 1Mb array is made inside your executable, working > but leading to a bloated >1Mb executable! ^^^^^^^^^^^^^^^^^^^^^^ > ^^^^^^^^^^^^^^^ > Third choice: malloc: dynamic, no disadvantages. > ^^^^^^^^^^^^^^^^ Wrong! [1] Static stuff is put to the .bss section, which is allocated by the DJGPP stub a loadtime. You can define a 16 meg static array and there will be *absolutely* mo exec size overhead. [2] malloc() from DJGPP C library only allocates blocks of sizes 2^n (for speed reasons). i.e., if you do malloc(1025), it actually allocates 2048 (2^11) and the rest (1023 minus some internal malloc structures) gets wasted. Ain't that a disadvantage? The only advantage is that you can catch a malloc() failure. In static array case, the program just would not load, exiting with an error message. Martynas