943,739 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1463
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 5th, 2009
0

Trouble finding enough RAM for malloc() in Vista 64?

Expand Post »
I'm having a lot of trouble finding enough RAM for a program I'm writing on Vista 64 Ultimate system, even though the system has 8GB RAM and only 2GB is used.

I tried to see how many 10 million byte blocks I could allocate using malloc(), and the compiled program crashes after the 209th block. So it crashes after just around 1.94GB of total memory allocated, despite the system having multiple more gigs of RAM available.

I don't know if the issue has to do with contiguous RAM or what. The same test program doesn't segmentation fault on a Linux system until after the 320th block, which should be because it's hitting the 3GB kernel limit for a process.

I've tried using various compilers, including the command line compiler for Visual Studio 2008, which I assume is a 64 bit compiler.

The actual program I'm working on needs a ton of memory for memory mapping data files about 800MB in size, and malloc() large arrays of the same size for numerical calculations. I actually moved from Linux to Windows because it was 64 bit with 8GB of memory.

What can I do to be able to use more RAM with malloc()?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Kadence is offline Offline
46 posts
since Dec 2004
Jul 5th, 2009
0

Re: Trouble finding enough RAM for malloc() in Vista 64?

>>Visual Studio 2008, which I assume is a 64 bit compiler.
No -- its a 32-bit compiler. But the Pro version can compile 64-bit code if you provide the right options. Just because you compile something on a 64-bit os doesn't mean you will automatically get a 64-bit program.

Post a short example program that produces the problem you are talking about.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Jul 5th, 2009
0

Re: Trouble finding enough RAM for malloc() in Vista 64?

I just tested a short program and it stopped at about 2Gig just as you had also reported. I believe the reason is a 32-bit program can only access 2 Gig RAM.

To get the 64-bit version of VC++ 2008 you have to select an option during installation. Here is how to do it.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Jul 5th, 2009
0

Re: Trouble finding enough RAM for malloc() in Vista 64?

(edit: whoops, you posted as I was reading that vcvarsall stuff I'll check out that link)

Thanks. The version I have is the Professional Edition. How do I use the 64-bit compiler? Do I change a setting somehow and use 'cl', or is there a flag to pass? I read How to: Enable a 64-Bit Visual C++ Toolset at the Command Line but didn't get how to actually use vcvarsall.bat.

Here's the code for my test program. It tries to allocate lots of arrays, and then assign a value to an element of the array (it's the assignment that causes the crash). The program crashes on my PC after the test207-test209, varying on different executions (not sure what that indicates). On Linux it seg faults after 320.
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(int argc, char *argv[]){
  6. double* test1 = (double*) malloc(10000000); test1[0] = 1.0; cout<<"Done 1"<<endl;
  7. double* test2 = (double*) malloc(10000000); test2[0] = 1.0; cout<<"Done 2"<<endl;
  8. double* test3 = (double*) malloc(10000000); test3[0] = 1.0; cout<<"Done 3"<<endl;
  9. ...
  10. double* test398 = (double*) malloc(10000000); test398[0] = 1.0; cout<<"Done 398"<<endl;
  11. double* test399 = (double*) malloc(10000000); test399[0] = 1.0; cout<<"Done 399"<<endl;
  12. double* test400 = (double*) malloc(10000000); test400[0] = 1.0; cout<<"Done 400"<<endl;
  13. }
Last edited by Kadence; Jul 5th, 2009 at 1:54 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
Kadence is offline Offline
46 posts
since Dec 2004
Jul 5th, 2009
0

Re: Trouble finding enough RAM for malloc() in Vista 64?

I don't know how to enable 64-bit. From what I see in the link I posted, and read in other places, its enabled during installation of the compiler. There is apparently an installation option that lets you install the 64-bit compiler. You may have to reinstall the compiler in order to get it.
Last edited by Ancient Dragon; Jul 5th, 2009 at 2:06 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Jul 5th, 2009
0

Re: Trouble finding enough RAM for malloc() in Vista 64?

All my Windows work is still under Win32.

Remember in 32-bit land you only have about 3.2Gig totally available to your application, which really works out to about 2Gig because Dev Studio is an oinker! It's a memory hog! Especially in a debug build.

You're using C++ compilers and using C memory allocation!

You should be using new/delete new[]/delete[]. Not Malloc Free.

For fun try GlobalAlloc(), under Vista 64. see how much it lets you allocate!
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jul 5th, 2009
0

Re: Trouble finding enough RAM for malloc() in Vista 64?

>>which really works out to about 2Gig because Dev Studio

What is Dev Studio? You mean Dev-C++? In any event it has nothing to do with the problem and does not affect the amount of memory a program can use, unless the computer has less than 2 Gig of RAM and is out of hard drive swap space.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Jul 5th, 2009
0

Re: Trouble finding enough RAM for malloc() in Vista 64?

Sorry I meant Visual Studio. (Dev Studio is a nickname for it!)
And Windows swaps out memory as you say, but DevStudio is the memory hog. Windows gives memory to the more active application and Visual Studio is a memory hog when it runs. Totally Shut down Visual Studio and run your test again as a standalone application.

Better yet, Reboot, then run your program and check your numbers!
Reputation Points: 546
Solved Threads: 99
Practically a Posting Shark
wildgoose is offline Offline
891 posts
since Jun 2009
Jul 5th, 2009
0

Re: Trouble finding enough RAM for malloc() in Vista 64?

Click to Expand / Collapse  Quote originally posted by wildgoose ...
Sorry I meant Visual Studio. (Dev Studio is a nickname for it!)
Never heard of that one?

Anyway: the real question is: Why would you ever want to use 2gb (!) of memory? I bet there's a better way to solve your problem then using 2gb of ram
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Jul 5th, 2009
1

Re: Trouble finding enough RAM for malloc() in Vista 64?

Seven Steps of Migrating a Program to a 64-bit System
Abstract. The article describes the main steps which should be performed to correctly port 32-bit Windows applications on 64-bit Windows systems. Although the article is meant for developers using C/C++ in Visual Studio 2005/2008 environment, it will be also useful for other developers who plan to port their applications on 64-bit systems.
Reputation Points: 46
Solved Threads: 3
Newbie Poster
Andrey_Karpov is offline Offline
7 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Completely Stuck on class project-- HELP!
Next Thread in C++ Forum Timeline: application decision program help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC