Solved

How to prevent using virtual memory

Posted on 2000-03-23
2
288 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 75 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
WinWaitActive parameters 12 31
Hibernate methods 2 58
Window placement 17 65
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now