Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GetMem vs VirtualAlloc

403 views
Skip to first unread message

Michael Lv

unread,
Dec 3, 2002, 12:36:47 AM12/3/02
to
Hi

In Borland's Documentation, routine GetMem() implements VirtualAlloc()
internally. But I write a demo and find GetMem only allocate 500M memory and
VirtualAlloc can allocate upper 1G memory in my 256M physical memory PC.

Anyone can try to access a Big file(size > your physical memory) with
GetMem() and see result.

My question is :
(1),Do GetMem() implement Virtual Memory Management internally? Need I
use VritualAlloc() straight?
(2), If (1) is No, so how can I implement Virtual Memory Management? Use
VirtualAlloc() or select a right Memory Manager in Delphi?

Thanks!

Michael Lv


Tomaz Koritnik

unread,
Dec 3, 2002, 4:50:35 AM12/3/02
to
Hi

For both functions a limit is 2GB. This is because in win32 enviroment,
all applications can allocate up to 2GB of memory (exactly 2^31 or 2^31 -
1). This, of course, is a virtual limit, whereas physical limit is the sum
of physical RAM and page file size.

Tomaz

"Michael Lv" <leisu...@263.net> wrote in message
news:3dec42c4$1...@newsgroups.borland.com...

Michael Kelly

unread,
Dec 3, 2002, 3:07:09 PM12/3/02
to
Michael Lv wrote:

> No, so how can I implement Virtual Memory Management? Use
> VirtualAlloc() or select a right Memory Manager in Delphi?

You might also want to check out the HeapAlloc() Win32 API.

--

"Only choice is an oxymoron."

Michael Lv

unread,
Dec 3, 2002, 9:50:33 PM12/3/02
to
I mean, although I can use VirtualAlloc() function to request virtual memory
allocation, but I can't control Delphi's internal memory management. For
instance, I create a class containing big string object. I write

MyObj := TMyObj.Create;

Can you tell me MyObj use heap memory or virtual memory?

Michael Lv


John Herbster \(TeamB\)

unread,
Dec 3, 2002, 11:09:13 PM12/3/02
to
"Michael Lv" <leisu...@263.net> wrote

> MyObj := TMyObj.Create;
> Can you tell me MyObj use heap memory or virtual memory?

Michael, I think that nearly all of a Windows' applications memory
can be swapped out to the disk swap area. I am guessing that that
is what you mean by virtual. I believe that there is a way to limit
such swapping, but I have never used it. Why were you asking?
Regards, JohnH


Michael Lv

unread,
Dec 4, 2002, 12:31:23 AM12/4/02
to
Thank you, John

Yes, MS use swapping files to implement virtual memory
management(right?). At past, I think GetMem() encapsulate internal virtual
memory management mechanism, so I use GetMem() function to access a 500M
file in my PC with only 256M physical memory. GetMem() can only allocate
about 400M memory for process and Windows raise "Out of Memory" exception.
I use VirtualAlloc() API to access file directly and make things better,
which can get upper 1G virtual memory. But I can't resolve such
memory-allocating like "TObject.Create", which be controlled by Delphi's
internal memory allocation mechanism. So my question is :
1, Can we believe GetMem() function for virtual memory allocation?
2, How can I manipulate memory allocation like "TObject.Create"?

Thanks!

scott_maskiel isat removeifnotspammer.nemmco.com.au

unread,
Dec 4, 2002, 3:12:52 AM12/4/02
to
memory-allocating like "TObject.Create", which be controlled by Delphi's
> internal memory allocation mechanism. So my question is :
> 1, Can we believe GetMem() function for virtual memory allocation?
> 2, How can I manipulate memory allocation like "TObject.Create"?
>
> Thanks!
>

Hi Michael,

Not sure about No. 1, but with No.2 you can declare your own class and
override the NewInstance method. NewInstance is responsible for
allocating an object's memory.

Regards,
Scott

0 new messages