delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/15/15:46:14

From: i96csm AT river DOT tay DOT ac DOT uk
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Large arrays eating disk space
Message-ID: <1997Oct15.115139.1@river.tay.ac.uk>
Date: 15 Oct 97 11:51:39 +0100
References: <Pine DOT GSO DOT 3 DOT 94 DOT 971012124635 DOT 6579A-100000 AT minerva DOT cis DOT yale DOT edu>
Organization: University of Abertay Dundee
Lines: 47
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <Pine DOT GSO DOT 3 DOT 94 DOT 971012124635 DOT 6579A-100000 AT minerva DOT cis DOT yale DOT edu>, "J. Hormuzdiar" <jimh AT pantheon DOT yale DOT edu> writes:
> Hello-
> 	Perhaps this question is better intended for comp.lang.c, but I am
> not sure yet.
> 
> 	I am using a djgpp/rhide environment with a program that has some
> huge fixed size arrays.  When I compile I get an executable that is
> correspondingly huge (many meg's), even though the code is pretty small.
> I assume that the compiler is saving the whole huge blank pre-used array
> in the executable, and I wish it wouldn't.  The space is a problem, but
> even worse is the wait for the compiler to save the huge thing every time.
> 
> 	I could just dynamically allocate using malloc, but I seem to
> remember that there is a keyword or option that will automatically do it
> for me.  Perhaps I could just add a word to the declaration-
> 
> (word) float x[7000][7000];
> 
> 	Thanks for your help.
> 
> 						-Jim
> 
> 
-- 
Fixed arrays are allocated in the program space.
To make the program smaller either move the array into main
or dynamically allocate it using malloc / new, like this


float **x;

void main(void)
{
  x=(float**)malloc(7000*7000*sizeof(float)); /* Allocate memory */
  if (x==NULL) /* Out of memory? */
  { 
    printf("Out of memory, aborting\n\n");
    exit(1);
  }

/* Do what ever your program does here */

  free(x); /* Release the memeory */


 return 0;
}

- Raw text -


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