Help: Large 3-d Arrays, work in unix, not in dos 
Author Message
 Help: Large 3-d Arrays, work in unix, not in dos

I am trying to write code that will create a 100x100x100 array
of structs of size 7.  for now, we can call them doubles as they
take roughly the same size.  i have code that will run on unix
in the following manner:

struct ThreeD * sphere[100][100];

for (i=0;i<100;i++){
   for (j=0;j<100;j++){
      sphere[i][j]=(struct ThreeD *)malloc(sizeof(struct ThreeD)*100);
      }
   }

i print out the pointers and they cycle through just fine.

i then try compiling it in borland c++4.5, with both a compact and
a huge memory model, also with and without the huge (or far)
keyword on the pointer, and i run out of memory.  the machine has
30 meg of extended memory free before i run the program.  i also
looked at the pointer locations, and every pointer has an offset
of 0004.  it would also work with a size of 20 instead of 100,
but that is not very helpful.

sort of weird and very perplexing and reminds me why i like
dos so much.

thanks for any help.

----------------------------------------------------------------

Robotics Ph.D. Student                  office: (412) 268-1416
Robotics Institute, CMU                 fax:    ???
http://www.*-*-*.com/ ~abm



Sat, 10 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos


Quote:
>I am trying to write code that will create a 100x100x100 array
>of structs of size 7.  for now, we can call them doubles as they
>take roughly the same size.  i have code that will run on unix
>in the following manner:

>struct ThreeD * sphere[100][100];

Your array exceeds the page size of the intel processor by and order of
magnitude. If you have to run on a dos box get djgpp the DOS verison of
the gnu C++ complier which will handle a 16 meg array, yours is 7 meg.

One of the other compilers that run in the protected mode may well work
but I only have experiance with djgpp.

Good luck
Gordon



Sat, 10 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos

Quote:
} I am trying to write code that will create a 100x100x100 array
} of structs of size 7.  for now, we can call them doubles as they
} take roughly the same size.  i have code that will run on unix
} in the following manner:
} struct ThreeD * sphere[100][100];
} for (i=0;i<100;i++){
}    for (j=0;j<100;j++){
}       sphere[i][j]=(struct ThreeD *)malloc(sizeof(struct ThreeD)*100);
}       }
}    }
} i print out the pointers and they cycle through just fine.
} i then try compiling it in borland c++4.5, with both a compact and
} a huge memory model, also with and without the huge (or far)
} keyword on the pointer, and i run out of memory.  the machine has
} 30 meg of extended memory free before i run the program.  i also
} looked at the pointer locations, and every pointer has an offset
} of 0004.  it would also work with a size of 20 instead of 100,
} but that is not very helpful.
} sort of weird and very perplexing and reminds me why i like
} dos so much.

You are trying to allocate more memory than DOS will allow.  You might
be trying to allocate about 14,000,000 bytes or so...DOH!  Can't be
helped in DOS.  Try splitting the array up into 640K bits and using
the _far allocates.

BTW, mod, how did this message get through your radar?

[I'm being mildly open about suggestions involving malloc; if it
 doesn't say "farmalloc", I'll assume they want a C answer, even if it's
 "no chance". -mod]
--

GCS/M/S d s-:+ a? C++++$ UL++>++++ P+++>+++++ L+++>+++++ E--- W-- N++ !o

!D G+ e++>+++++ h(++) !r !y+



Sun, 11 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos
 >
 > I am trying to write code that will create a 100x100x100 array
 > of structs of size 7.  for now, we can call them doubles as they
 > take roughly the same size.  i have code that will run on unix
 > in the following manner:
 >
 > struct ThreeD * sphere[100][100];
 >
 > for (i=0;i<100;i++){
 >    for (j=0;j<100;j++){
 >       sphere[i][j]=(struct ThreeD *)malloc(sizeof(struct ThreeD)*100);
 >       }
 >    }
 >
 > i print out the pointers and they cycle through just fine.
 >
 > i then try compiling it in borland c++4.5, with both a compact and
 > a huge memory model, also with and without the huge (or far)
 > keyword on the pointer, and i run out of memory.  the machine has
 > 30 meg of extended memory free before i run the program.  i also
 > looked at the pointer locations, and every pointer has an offset
 > of 0004.  it would also work with a size of 20 instead of 100,
 > but that is not very helpful.
 >
 > sort of weird and very perplexing and reminds me why i like
 > dos so much.
 >
 > thanks for any help.
 >
 > ----------------------------------------------------------------

 > Robotics Ph.D. Student                  office: (412) 268-1416
 > Robotics Institute, CMU                 fax:    ???
 > http://www.cs.cmu.edu/~abm
I think this the the problem of 16-bit compiler, if you use 32-bit
compiler you can avoid this problem easily.  100*100*7=70000 >64KB.
Try a 96*96*96 array, if you can succeed, I will be right.

Oh, sorry, I forget that you are going to use your program on DOS
platform. You see, under DOS, you can't use XMS directly, so no
matter how much free XMS you have, you can't allocate large array
in a normal way just like yours, a large sum of technology must be
paid to gain access to XMS under pure DOS with HIMEM.SYS driver.

You can only try a 96*96*5 array, I guess.

[followups to comp.os.msdos.programmer. -mod]



Sun, 11 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos


 > I am trying to write code that will create a 100x100x100 array
 > of structs of size 7.  for now, we can call them doubles as they
 > take roughly the same size.  i have code that will run on unix
 > in the following manner:
 >
 > struct ThreeD * sphere[100][100];
 >
 > for (i=0;i<100;i++){
 >    for (j=0;j<100;j++){
 >       sphere[i][j]=(struct ThreeD *)malloc(sizeof(struct ThreeD)*100);
 >       }
 >    }
 >
 > i print out the pointers and they cycle through just fine.
 >
 >
 > i then try compiling it in borland c++4.5, with both a compact and
 > a huge memory model, also with and without the huge (or far)
 > keyword on the pointer, and i run out of memory.  the machine has
 > 30 meg of extended memory free before i run the program.  i also
 > looked at the pointer locations, and every pointer has an offset
 > of 0004.  it would also work with a size of 20 instead of 100,
 > but that is not very helpful.
 >
 > sort of weird and very perplexing and reminds me why i like
 > dos so much.

First of all, can I refer you to the standard. Section 5.2.4.1
Translation Limats contains "The implementation shall be able to
translate and execute at least one program that contains at least one
instance of every one of the following limits: ... 32767 bytes in an
object.  sphere is a 40000 byte object!

Your DOS program is limited to running in the unused portion of memory
below 640K.  You are looking for storage for 1E6 of (struct ThreeD).
You need a DOS extender.
--
walter briscoe



Mon, 12 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos


: i then try compiling it in borland c++4.5, with both a compact and
: a huge memory model, also with and without the huge (or far)
: keyword on the pointer, and i run out of memory.  the machine has
: 30 meg of extended memory free before i run the program.  i also
: looked at the pointer locations, and every pointer has an offset
: of 0004.  it would also work with a size of 20 instead of 100,
: but that is not very helpful.

It's called the 640k memory boundry.  Heap is only allocated out of that
640k.  You will either have to use EMS, XMS, DPMI, etc if you want to
access more than your conventional memory.

(Or throw the processor into protected mode and do it yourself!)

Later,

Dave

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Dave Frascone                                      Phone: (770) 623-2450
Design Engineer                                    Fax:   (770) 497-3990



Mon, 12 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos


 >
 >
 >: i then try compiling it in borland c++4.5, with both a compact and
 >: a huge memory model, also with and without the huge (or far)
 >: keyword on the pointer, and i run out of memory.  the machine has
 >: 30 meg of extended memory free before i run the program.  i also
 >: looked at the pointer locations, and every pointer has an offset
 >: of 0004.  it would also work with a size of 20 instead of 100,
 >: but that is not very helpful.
 >
 >
Even using DPMI will lead to some memory problems. Your memory consumption
is about 26.7 MB (using large memory models or 32 Bit environment
: 4*100*100 for the table and 7*100 for structs ). Under DOS you will
have to swap to disk. Even on my own Linux installation (24 MB swap
partition ) I would get some problems ( but I didn't test it).

Damian




Tue, 13 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos

: : i then try compiling it in borland c++4.5, with both a compact and
: : a huge memory model, also with and without the huge (or far)
: : keyword on the pointer, and i run out of memory.  the machine has
: : 30 meg of extended memory free before i run the program.  i also
: : looked at the pointer locations, and every pointer has an offset
: : of 0004.  it would also work with a size of 20 instead of 100,
: : but that is not very helpful.

: It's called the 640k memory boundry.  Heap is only allocated out of that
: 640k.

Even then, in a plain DOS program, you still can't have any one object
bigger than 64K.

Scott



Thu, 15 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos



Quote:

>: : i then try compiling it in borland c++4.5, with both a compact and
>: : a huge memory model, also with and without the huge (or far)
>: : keyword on the pointer, and i run out of memory.  the machine has
>: : 30 meg of extended memory free before i run the program.  i also
>: : looked at the pointer locations, and every pointer has an offset
>: : of 0004.  it would also work with a size of 20 instead of 100,
>: : but that is not very helpful.
>: It's called the 640k memory boundry.  Heap is only allocated out of that
>: 640k.
>Even then, in a plain DOS program, you still can't have any one object
>bigger than 64K.

     Not so!  Compile with the huge memory model.

Sincerely,

Gene Wirchenko

C Pronunciation Guide:
     y=x++;     "wye equals ex plus plus semicolon"
     x=x++;     "ex equals ex doublecross semicolon"



Sat, 17 Oct 1998 03:00:00 GMT  
 Help: Large 3-d Arrays, work in unix, not in dos




 >
 >: : i then try compiling it in borland c++4.5, with both a compact and
 >: : a huge memory model, also with and without the huge (or far)
 >: : keyword on the pointer, and i run out of memory.  the machine has
 >: : 30 meg of extended memory free before i run the program.  i also
 >: : looked at the pointer locations, and every pointer has an offset
 >: : of 0004.  it would also work with a size of 20 instead of 100,
 >: : but that is not very helpful.
 >
 >: It's called the 640k memory boundry.  Heap is only allocated out of that
 >: 640k.
 >
 >Even then, in a plain DOS program, you still can't have any one object
 >bigger than 64K.
 >
 >Scott

I use the _huge keyword to declare pointers to objects larger than 64K,
I use farmalloc() to create the objects and build my program with the
huge memory model.
Works fine (within the constraints of the 640K limit) with Borland and
Microsoft.
Am I missing something here?

[Probably not, but followups are now set to comp.os.msdos.programmer. -mod]

--
Paul Robertson



Sat, 17 Oct 1998 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Help: Large 3-d Arrays, work in unix, not in dos

2. Works in DOS and not in UNIX

3. Help Novice on large arrays in DOS

4. Large arrays in Unix

5. Large Arrays under DOS Borland C++ v5.02

6. Large Arrays in MS-DOS Environment

7. Question : xalloc'ing a large (128K) char array (MS-DOS)

8. A problem with very large arrays and memory in DOS-based C

9. Help !!! Concat small array into large array

10. Making VAX/VMS C work like MS-DOS and UNIX C

11. ? array too big in dos ok in unix

12. same code compiles in DOS but not in UNIX

 

 
Powered by phpBB® Forum Software