Solved

How to prevent using virtual memory

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
Get filename and folder into excel 7 68
centeredAverage challenge 8 130
sumHeights  challenge 17 65
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 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