Thread: memory question

  1. #1
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26

    memory question

    i want to know how i create a dynamic matrix but i want to alloc it on the ram not the heap

    here's some the code i have:

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    void main (void)
    {
     int **m;
    
     m = new int *[3];
     for (int i=0; i<3;i++)
         m[i]=new int [4];
    
     for (i=0; i<3;i++)
         delete [] m[i];
     delete [] m;
    }
    if i create a big matrix like 1000x1000 i run out of memory help me plz....
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You are only allowed to access up to 1024 KB in real mode. Also, DOS will limit that to 640KB. The only way to gain more is to either move to protected mode or to access more memory via HIMEM.SYS (XMS) or EMM386.EXE (EMS).

    Protected mode is the easiest, but second to that is EMS. EMS is very simple to use. Check out an interrupt listing for more information about how to use either EMS or XMS. Ralf Brown's interrupt listing is great.

    http://www-2.cs.cmu.edu/~ralf/files.html

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Why would you need to have it specifically on the RAM. What's the difference between that and the heap?

  4. #4
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26
    as i belive...

    heap in c++ (under DOS) is the first 640 kB and i got to alloc about 5mb, so i ran out of memory (i can't alloc everything i need), and also i can't make new dynamic variables...

    must be a way to alloc a lot of memory i need at least 5mb...
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  5. #5
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26
    hey try this code....


    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <string.h>
    
    void main (void)
    {
     int **m;
    
     m = new int *[1000];
     for (int i=0; i<1000;i++)
         m[i]=new int [1000];
    
    
      char *test = new char[30];
      strcpy(test, "This won't work!")
       //as you see i can't ask for more memory and the "m" isn't 1000x1000
       // i there must be a way to do that...
    
    
     for (i=0; i<1000;i++)
         delete [] m[i];
     delete [] m;
    
    }

    this question is to fill the matrix with getpixel()... is for make something like a virtual screen....
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I just told you how to do it. Use EMS.

  7. #7
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26
    sorry, but i didn't understand how the files in the url you toll me works...
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. heap vs stack memory question
    By donglee in forum C++ Programming
    Replies: 4
    Last Post: 01-23-2009, 04:34 PM
  2. Pointer memory question
    By Edo in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2009, 03:36 AM
  3. Memory question
    By John_L in forum Tech Board
    Replies: 8
    Last Post: 06-02-2008, 10:06 PM
  4. Another Dynamic Memory Question
    By SirCrono6 in forum C++ Programming
    Replies: 6
    Last Post: 03-02-2005, 12:10 PM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM