I'm having problems with even small amounts of allocated memory in my programs being swapped out to disk using Windows XP. This is affecting the speed of my routines greatly.

I understand that VirtualLock should help. Is it supported under HLA?
Posted on 2003-05-11 11:33:59 by V Coder

I'm having problems with even small amounts of allocated memory in my programs being swapped out to disk using Windows XP. This is affecting the speed of my routines greatly.

I understand that VirtualLock should help. Is it supported under HLA?


You can call any Win32 API function from HLA.
Most of the definitions should already be in the w.hhf header file (or the subserviant
files it includes, like kernel32.hhf, user32.hhf, etc.). If a function is missing, it's fairly
easy to add it to the include file by looking at the C template for that function and
writing an equivalent HLA prototype. Being able to do this is an important part of
programming Windows in assembly, so important, in fact, that I devoted over 100 pages
in my next book (Windows Programming in Assembly) to describing how to convert
C code to assembly for this very purpose.

VirtualLock, however, is already defined in the kernel32.hhf header file, so all you've
got to do is include "w.hhf" and you can call the w.VirtualLock function.
The "kernelref.pdf" or "kernelref.html" files in the HLA documentation download
describe this function.
Cheers,
Randy Hyde
Posted on 2003-05-11 20:53:17 by rhyde
Thanks much. I have quite a bit of reading and experimenting ahead of me.
Posted on 2003-05-12 00:16:11 by V Coder
Randy,

Here is my HLA implementation of VirtualLock...



// GetCurrentProcess
w.GetCurrentProcess();
mov (eax, ebx);
// GetProcess Sizes
w.GetProcessWorkingSetSize(ebx, minsz, maxsz);

console.gotoxy(12, 1);
stdout.put("WorkingSetSize ", minsz, " ", maxsz);

add (memtoalloc, minsz); // Increase minimum
add (memtoalloc, maxsz); // and maximum memory
// to be kept active by virtual memory manager
// Reset Process Sizes + memtoalloc
w.SetProcessWorkingSetSize(ebx, minsz, maxsz);

stdout.put(" WorkingSetSize reset to ", minsz, " ", maxsz);

// Allocate RAM; EAX contains address
w.VirtualAlloc(NULL, memtoalloc, $1000, $4); // MEM_COMMIT, PAGE_READWRITE
test (eax, eax);
jne okay;
console.gotoxy(13, 1);
stdout.put("Unable to allocate memory needed.");
jmp exittt;

okay:
// Store memory address
mov (eax, memaddr);
add (8, eax);
mov (eax,high1);
add (memhalf,eax);
mov (eax,high2);

console.gotoxy(13, 1);
stdout.put("Memory allocated at ", memaddr);

// Lock the memory into physical memory
w.VirtualLock(val memaddr, memtoalloc);
test (eax, eax);
jne okay2;
console.gotoxy(14, 1);
stdout.put("Unable to lock memory.");
jmp exittt;

okay2:


Problem:
The correct syntax should be w.VirtualLock(memaddr, memtoalloc);
But, the program responds unable to lock memory.

There is no such response if I use w.VirtualLock(val memaddr, memtoalloc);
However, there is no improvement in the paging characteristics of my code.

HELP!!!!!!!!!!!
Posted on 2003-05-14 19:52:54 by V Coder

Randy,

Here is my HLA implementation of VirtualLock...


Problem:
The correct syntax should be w.VirtualLock(memaddr, memtoalloc);
But, the program responds unable to lock memory.

There is no such response if I use w.VirtualLock(val memaddr, memtoalloc);
However, there is no improvement in the paging characteristics of my code.

HELP!!!!!!!!!!!


Because w.VirtualLock passes the first parameter as untyped reference,
it will take the address of whatever memory object you supply as the first
parameter, even if this is a pointer variable (that is, it will take the address
of the pointer, not use the pointer which is the address of the block of memory
you use). Therefore, the correct syntax really is "val memaddr" for the first parameter
(so it will use the *value* of this pointer rather than its address).
Now, as to why this isn't improving the paging characteristics is not something I can
answer. However, HLA is not providing a "wrapper" to this function, the w.VirtualLock
declaration is simply a prototype for the actual Windows API function.

Have you verified that Windows *is* paging this memory to disk when you lock it?
Also, don't forget that if you were having thrashing problems before and you lock a page
down, what you're really doing is pushing the thrashing somewhere else. That may
be what you're observing. Can't say for sure, though, because I'm not intimately
familiar with Window's paging algorithms.
Cheers,
Randy Hyde
Posted on 2003-05-20 12:48:23 by rhyde
Thanks. I'm looking into the paging issue. It seems to really only affect Windows XP.
Posted on 2003-05-21 03:59:39 by V Coder