Board index » cppbuilder » Re: Memory problems: new versus GlobalAlloc

Re: Memory problems: new versus GlobalAlloc


2005-03-24 08:59:52 PM
cppbuilder100
(lines with begin are handled specially???)
TotalAddrSpace TotalUncommitted TotalCommitted
Xbegin 1.048.576 950.272 98.304
size=921600 2.097.152 1.064.960 1.032.192
end 1.048.576 950.272 98.304
result 0 0 0
begin 1.048.576 966.656 81.920
size=921600 1.048.576 32.768 1.015.808
end 1.048.576 966.656 81.920
result 0 0 0
begin 1.048.576 966.656 81.920
size=921600 1.048.576 16.384 1.032.192
end 1.048.576 966.656 81.920
result 0 0 0
begin 1.048.576 950.272 98.304
size=921600 2.097.152 1.048.576 1.048.576
end 1.048.576 933.888 114.688
result 0 -16.384 16.384
begin 1.048.576 933.888 114.688
size=921600 2.097.152 1.032.192 1.064.960
end 1.048.576 933.888 114.688
result 0 0 0
begin 1.048.576 933.888 114.688
size=921600 2.097.152 1.032.192 1.064.960
end 2.097.152 1.966.080 131.072
result 1.048.576 1.032.192 16.384 Not zero, the next time
an error
begin 2.097.152 1.966.080 131.072
size=921600 3.145.728 2.064.384 1.081.344
(0) Result=0 Access denied. (this doesn't make sense and sometimes I get a
message not enough memory)
end 2.097.152 1.966.080 131.072
result 0 0 0
If I add a TImage to the form and do
Image1->Picture->Assign(Bitmap);
just before deleting the buffer, the error occurs almost direct:
begin 1.048.576 999.424 49.152
size=921600 1.048.576 49.152 999.424
end 1.048.576 983.040 65.536
result 0 -16.384 16.384 Not zero, but this is the
very first time, no error
begin 1.048.576 983.040 65.536
size=921600 2.097.152 1.081.344 1.015.808
end 2.097.152 2.015.232 81.920
result 1.048.576 1.032.192 16.384 Not zero, the next time an
error
begin 2.097.152 2.015.232 81.920
size=921600 3.145.728 2.113.536 1.032.192
(0) Result=0 Access denied.
end 3.145.728 3.063.808 81.920
result 1.048.576 1.048.576 0
begin 3.145.728 3.063.808 81.920
size=921600 3.145.728 2.113.536 1.032.192
end 2.097.152 2.031.616 65.536
result -1.048.576 -1.032.192 -16.384
begin 2.097.152 2.031.616 65.536
size=921600 2.097.152 1.081.344 1.015.808
end 2.097.152 2.015.232 81.920
result 0 -16.384 16.384
begin 2.097.152 2.015.232 81.920
size=921600 3.145.728 2.113.536 1.032.192
(1) Result=0 Access denied.
end 3.145.728 3.047.424 98.304
result 1.048.576 1.032.192 16.384
 
 

Re:Re: Memory problems: new versus GlobalAlloc

(sorry for the fuzz. please let someone delete the wrong mailes for me)
"Bob Gonder" < XXXX@XXXXX.COM >wrote
<snip>
Quote
You never check if new or GlobalAlloc succeed in allocating Buffer.
Ok, so I did that and noticed that GetDIB failes sometimes. I cannot find
any reason for this failure but I suspect Borlands memory manager or page
swapping is the problem.
The program adds a TMemoryStream with a JPEG image to a THeapList.
In the main thread I check for an object and render it to screen.
In this method, I checked the HeapStatus.
Looking at the results below I cannot understand why there is sometimes a
difference between begin and end. It looks like the memory manager doesn't
free the memory block or doesn't re-use it or so. I've noticed that Borland
uses VirtualAlloc and VirtualFree. Both allocate page swapable memory.
Here are the results. Half way the method, I allocate memory for the buffer.
Just before the error occurs, there's a difference between end and begin.
Result (the difference) show some values, where I should think they should
all be zero.
(best viewed with a fixed font)
TotalAddrSpace TotalUncommitted TotalCommitted
Xbegin 1.048.576 950.272 98.304
size=921600 2.097.152 1.064.960 1.032.192
end 1.048.576 950.272 98.304
result 0 0 0
Xbegin 1.048.576 966.656 81.920
size=921600 1.048.576 32.768 1.015.808
end 1.048.576 966.656 81.920
result 0 0 0
Xbegin 1.048.576 966.656 81.920
size=921600 1.048.576 16.384 1.032.192
end 1.048.576 966.656 81.920
result 0 0 0
Xbegin 1.048.576 950.272 98.304
size=921600 2.097.152 1.048.576 1.048.576
end 1.048.576 933.888 114.688
result 0 -16.384 16.384
Xbegin 1.048.576 933.888 114.688
size=921600 2.097.152 1.032.192 1.064.960
end 1.048.576 933.888 114.688
result 0 0 0
Xbegin 1.048.576 933.888 114.688
size=921600 2.097.152 1.032.192 1.064.960
end 2.097.152 1.966.080 131.072
result 1.048.576 1.032.192 16.384 Not zero, the next time
an error
Xbegin 2.097.152 1.966.080 131.072
size=921600 3.145.728 2.064.384 1.081.344
(0) Result=0 Access denied. (this doesn't make sense and sometimes I get a
message not enough memory)
end 2.097.152 1.966.080 131.072
result 0 0 0
If I add a TImage to the form and do
Image1->Picture->Assign(Bitmap);
just before deleting the buffer, the error occurs almost direct:
Xbegin 1.048.576 999.424 49.152
size=921600 1.048.576 49.152 999.424
end 1.048.576 983.040 65.536
result 0 -16.384 16.384 Not zero, but this is the
very first time, no error
Xbegin 1.048.576 983.040 65.536
size=921600 2.097.152 1.081.344 1.015.808
end 2.097.152 2.015.232 81.920
result 1.048.576 1.032.192 16.384 Not zero, the next time an
error
Xbegin 2.097.152 2.015.232 81.920
size=921600 3.145.728 2.113.536 1.032.192
(0) Result=0 Access denied.
end 3.145.728 3.063.808 81.920
result 1.048.576 1.048.576 0
Xbegin 3.145.728 3.063.808 81.920
size=921600 3.145.728 2.113.536 1.032.192
end 2.097.152 2.031.616 65.536
result -1.048.576 -1.032.192 -16.384
Xbegin 2.097.152 2.031.616 65.536
size=921600 2.097.152 1.081.344 1.015.808
end 2.097.152 2.015.232 81.920
result 0 -16.384 16.384
Xbegin 2.097.152 2.015.232 81.920
size=921600 3.145.728 2.113.536 1.032.192
(1) Result=0 Access denied.
end 3.145.728 3.047.424 98.304
result 1.048.576 1.032.192 16.384
 

Re:Re: Memory problems: new versus GlobalAlloc

Wim Bekker wrote:
Quote
(sorry for the fuzz. please let someone delete the wrong mailes for
me)
You can delete your own posts, actually.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

{smallsort}

Re:Re: Memory problems: new versus GlobalAlloc

Reading through more documentation and newsgroups, I've noticed that
Borlands new uses VirtualAlloc. Some calls to new, especially when asking a
lot of memory use more than one call to VirtualAlloc to get one block.
Maybe the block is devided on several pages that are swapped to and from
disk.
GetDIB, StretchDIBits etc cannot handle this. They need a block that is
continous, for example one from GlobalAlloc.
This explains why GlobalAlloc works when allocating a buffer and new doesn't
work.
Wim