🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5929

Re: Full Access to 2 GB memory RAM ?

#5929
From: Arnie
Date: Sun, 26 Jun 2005 15:08
80 lines
3717 bytes
"Deniel" <DenielMail@Internet.com> wrote in message 
news:42be94fa$1@newsgroups.borland.com...
>
> Hi again :-)
>
> Using Builder 4.0 C++ on XP computer, if my PC have 2 GB of RAM
> memory, can i write in my program -
>
> int *MyBuffer = new int[0.85 * ( 2 ^ 31 )];
>
> and expect that this buffer will sit whole on the RAM (without
> paging to the Hard-Disk) and that i'll have full access to all
> it's cells from  MyBuffer[0] till MyBuffer[1825361100] ?
>
> Thanks very much!
>
> Dani.
Chances are real good you won't be able to allocate that much 
memory in one block.  Even if you could, you'll be paging to 
disk.  As others have said in reply to your previous post, how 
the data is accessed is also important - sequential is good, 
random is bad.

Why not just try it instead of asking questions?  Here is a 
simple console program, no VCL, no multithreading (BCB 5).

#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
   size_t i;
   const size_t blockSize = 100000000;
   unsigned char * mem;

   for ( i = 1; i <= 20; ++i )
   {
      try
      {
         mem = new unsigned char[i * blockSize];
         memset( static_cast<void *>(mem), 0, i * blockSize );
         cout << "Allocated " << i * blockSize << " bytes." << 
endl;
         delete [] mem;
      }
      catch( const std::exception & e )
      {
         cout << e.what() << endl;
         return 16;
      }
   }
 return 0;
}

My laptop has 1 GB RAM.  The largest block I can allocate is 
1,100,000,000.  And that takes some patience.

32 bit Windows allows for 4 GB virtual memory.  By default, the 
top 2 GB is for the OS, the lower 2 GB is for the application. 
You can change this on some versions of Windows so that the OS 
will use the top 1 GB and the application will have the lower 3 
GB available.  This is accomplished by using the /3GB switch in 
boot.ini (root boot directory).  It's probably system/hidden/read 
only.  Then the EXE must have the LARGEADDRESSAWARE switch set in 
its header.  You can find how to do this at MSDN along with which 
versions of Windows supports it.  I know that XP Pro with SP1 or 
SP2 does (I forget which is required).  We use it on W2K3 server 
and can access about 2.8 GB, though not all in one piece.  And 
that's with Visual C++.  BCB 5 doesn't do as well.

Beyond this, you'll have to go to an AIX, Linux or other OS, with 
a 64 bit processor and at least 8 GB of RAM installed.  Note that 
MS has W2K3 and XP x64 versions available but they're not ready 
for prime time yet (my opinion) due to a lack of drivers. 
However, a 32 bit program running on XP Pro x64 should be able to 
make nearly 4 GB available to your app.  However, you should 
still have at least 8 GB installed.

Good luck,
- Arnie 
Technical Details
Message-ID: <42bec588$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42be94fa$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,256f8494310fe6f6
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Arnie" <none>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <42be94fa$1@newsgroups.borland.com>
Subject: Re: Full Access to 2 GB memory RAM ?  
Date: Sun, 26 Jun 2005 11:08:12 -0400
Lines: 82
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 24.151.53.204
Message-ID: <42bec588$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1119798664 24.151.53.204 (26 Jun 2005 08:11:04 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail