delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/07/13:26:08

Xref: news2.mv.net comp.os.msdos.djgpp:6781
From: C M Marka <matriu AT gim DOT ktu DOT lt>
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: <Pine.HPP.3.91.960803160943.7717A-100000@santaka.sc-uni.ktu.lt>
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
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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019