Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

too much global data defined in file

57 views
Skip to first unread message

adric22

unread,
Sep 12, 2009, 1:29:12 PM9/12/09
to
How do I allocate an array that is about 64K in size using turbo-C?
It gives me the error "too much global data defined in file."

pe...@nospam.demon.co.uk

unread,
Sep 13, 2009, 1:54:31 AM9/13/09
to
In article <eaa8f518-f794-4dea...@y21g2000yqn.googlegroups.com>
adr...@yahoo.com "adric22" writes:

> How do I allocate an array that is about 64K in size using turbo-C?
> It gives me the error "too much global data defined in file."

I'm not familiar with Turbo-C, but you could try specifying Large
or Huge model. Or maybe Compact model if it's supported and
appropriate for your code.

Pete
--
"We have not inherited the earth from our ancestors,
we have borrowed it from our descendants."

Alex Russell

unread,
Sep 13, 2009, 2:52:15 AM9/13/09
to
pe...@nospam.demon.co.uk wrote:
> In article <eaa8f518-f794-4dea...@y21g2000yqn.googlegroups.com>
> adr...@yahoo.com "adric22" writes:
>
>> How do I allocate an array that is about 64K in size using turbo-C?
>> It gives me the error "too much global data defined in file."
>
> I'm not familiar with Turbo-C, but you could try specifying Large
> or Huge model. Or maybe Compact model if it's supported and
> appropriate for your code.
>
> Pete
large model - far data and code
medium - near data, far code
compact - far data, near code
small - near data, near code
tiny - data and code in same segment

char *t1;
char *at1;

t1=malloc(number_of_bytes);

/* use t1 */
*t1='a';
for ( i=0; i < number_of_bytes; i++ )
t1[i]=0;
at1=t1;
for ( i=0; i < number_of_bytes; i++ )
*at1++=0;

free(t1);
t1=NULL;


Alex

adric22

unread,
Sep 13, 2009, 2:57:20 PM9/13/09
to
> char *t1;
> char *at1;
>
> t1=malloc(number_of_bytes);
>
> /* use t1 */
> *t1='a';
> for ( i=0; i < number_of_bytes; i++ )
>         t1[i]=0;
> at1=t1;
> for ( i=0; i < number_of_bytes; i++ )
>         *at1++=0;
>
> free(t1);
> t1=NULL;


Thanks for the help... but I'm not getting how to use this. Where do
I specify these large, medium, compact, etc?

Also, I tried using the malloc() but I'm not sure where to put that.
Does it go in the global variable space, or in an actual procedure as
part of the code? I tried it both ways and got an error. I tried
this:

unsigned char *variablespace;
variablespace=malloc(65535);

but it complained and gave two errors:
1) declaration needs type or storage class.
2) type mismatch in redeclaration of 'viarablespace'

Essentially I'm trying to create a large array called variablespace
that is at least 64K in size. I looked at that code snippet there,
but I am not entirely sure what you are showing me.

Alex Russell

unread,
Sep 13, 2009, 6:39:47 PM9/13/09
to


If you are using the IDE the "memory model" will be one of the global
compilation options. The memory model controls what kind of default
pointer (far or near) is used for code and data.

large is often a good choice is there is a lot of code and data.

malloc is used right in the c code, often right in the function where
the memory is used. malloc returns a chunk of memory that can be used by
your program. malloc returns a POINTER to the memory.


here is an example of using an array, statically declared and
dynamically declared.

#define STR_LEN 127
#define NUM_FOOS 100

typedef struct
{
int x,y,z;
char str[STR_LEN+1];
}
foo_t;


/* static */

foo_t lots_of_foo[NUM_FOOS];
int i;

for ( i=0; i < NUM_FOOS; i++ )
{
lots_of_foo[i].x=100;
lots_of_foo[i].y=1;
lots_of_foo[i].z=22;
strcpy(lots_of_foo[i].str, "a string");
}

/* dynamic */

foo_t foo_pointer, *ft;
int i;

foo_pointer=malloc(sizeof(foo_t * NUM_FOOS);
/* malloc allocates bytes */
/* foo_pointer points toa region of memory big enough to hold 100 foo_
structures */

/* access foo_pointer using pointer syntax */
for ( ft=foo_pointer, i=0; i < NUM_FOOS; i++, ft++ )
{
ft->x=123;
ft->y=22;
ft->z=77;
strcpy(ft->str, "a string");
}

/* and showing how pointers can be treated like arrays */
for ( i=0; i < NUM_FOOS; i++ )
{
foo_pointer[i].x=45;
foo_pointer[i].y=22;
strcpy(foo_pointer[i], "a string");
}

free(foo_pointer); /* once all done with the memory, free it so it can
be used again for something else */


ft++
c knows ft points to a foo_t so the ++ operator adds the siz eof foo_t
to the pointer, and it now to the next structure.

Alex

0 new messages