?
Solved

How to prevent using virtual memory

Posted on 2000-03-23
2
Medium Priority
?
310 Views
Last Modified: 2013-12-26
Dear All:
    I have to allocate large memory to do date transfer through SCSI equipment.I allocate memory through standard memory function and sometimes get the virtual memory.
    The SCSI action will crash the system using virtual memory.  
    Is there any method to prevent get virtual memory or to recognize how much physical memory is left in my application's heap So that I can allocate memory smaller than that size
   Thank In advanced

Best Regards
Te-Lieh
.    
0
Comment
Question by:TeLieh
  • 2
2 Comments
 
LVL 4

Expert Comment

by:Alex Curylo
ID: 2651868
Well, that's a start, but that's not going to stop your crashes by itself. The real trick to watch out for here is that other applications or the System might cause a page out your buffer behind your back, even if you are careful about physical memory size. What you should do is around your sensitive calls call

FUNCTION HoldMemory (address: UNIV Ptr; count: LongInt): OSErr;

to ensure that your buffer is actually in RAM until you call UnholdMemory().

Note that this is not just a good idea, it's the LAW. The VM chapter of IM says

"During the time that the Macintosh is handling a page fault, it is critical that no other page faults occur. Because the system performs no other work while it is handling a page fault, only code that runs as a result of an interrupt can generate a second page fault. For this reason, you must call the HoldMemory function on buffers or code that are to be referenced by any interrupt service routine. You must call this function at noninterrupt level because the MemoryDispatch calls may cause movement of logical memory or physical memory and possible I/O."

Your SCSI read buffer almost certainly is referenced by an interrupt service routine. And that would explain your crashes quite nicely :)

I strongly suggest you read through the Virtual Memory chapter of Inside Macintosh, which documents the above and probably lots of other stuff you should know, found on the Web at

http://developer.apple.com/techpubs/mac/Memory/Memory-151.html

Now, as for the actual question you asked, that's easy, just call Gestalt(), I'm sure you've run into that routine already, with the gestaltPhysicalRAMSize selector.
0
 
LVL 4

Accepted Solution

by:
Alex Curylo earned 300 total points
ID: 2651871
Bah. That last was an ANSWER, not a COMMENT. Stupid default forms. Read that and then accept this if that's good enough for you, please :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question