[Wine] Re: malloc small pieces of memory

Johannes Holzer hl.ichaus at arcor.de
Wed Jun 28 07:58:34 CDT 2006


Geoff Streeter schrieb:
> At 2006-06-27 10:26 +0200, Johannes Holzer wrote:
> 
> Does this program use any other memory allocation functions, like
> VirtualAlloc(), or mapped files? If it is trying to predict how much
> memory is available and then allocating address space (without
> committing it) there might not be enough address space left for new
> malloc areas. Does the program use threads? How does it determine the
> stack space requirement for its threads?
> 
> There are windows routines that will enumerate the virtual memory
> allocation. Using them prior to displaying the dialog box may give you a
> lot more insight into what may be happening. Note that malloc uses these
> blocks and that it allocates reasonable sized blocks from which to serve
> up small malloc()s.
> 

Well, okay, reading this i started to create a testcase to see the
isolated problem. It seems, that the wine-malloc function behave
differently than malloc with windows.

In the testcase:
1. Allocate three large pieces of memory.
2. Free the second (hopefully middle) piece of memory.
3. Allocate the same size again.

I expect: (3) uses the same memory pointer than the one which was freed
in (2). This is what i get under windows.

With wine, (3) gets a new piece of memory.
This failes, if the pieces are large enough (here: 300 MB), so that
3xMEMSIZE fits into the (virtual) memory, but not 4xMEMSIZE.

And here's my testcase (see Attachements):
Sourcecode: hl_testcase.cpp	
Output (windows): stdout_windows.txt
Output (wine): stdout_wine.txt

I have used some debug options of wine:
  export WINEDEBUG=warn+all,+heap
then i get a lot of debug output, here is the interesting part:

------------------------------------------------------------------
Allocating 3x 300 MB Virtual Memory...
trace:heap:HEAP_FindFreeBlock created new sub-heap 0x40870000 of
12c00030 bytes for heap 0x40380000
trace:heap:RtlAllocateHeap (0x40380000,00000002,12c00000): returning
0x40870020
trace:heap:HEAP_FindFreeBlock created new sub-heap 0x53480000 of
12c00030 bytes for heap 0x40380000
trace:heap:RtlAllocateHeap (0x40380000,00000002,12c00000): returning
0x53480020
trace:heap:HEAP_FindFreeBlock created new sub-heap 0x66090000 of
12c00030 bytes for heap 0x40380000
trace:heap:RtlAllocateHeap (0x40380000,00000002,12c00000): returning
0x66090020
Freeing middle piece of memory..
trace:heap:RtlFreeHeap (0x40380000,00000002,0x53480020): returning TRUE
Allocating same size again..
warn:heap:HEAP_CreateSubHeap Could not allocate 12c10000 bytes
trace:heap:RtlAllocateHeap (0x40380000,00000002,12c00000): returning NULL
trace:heap:RtlAllocateHeap (0x40380000,0000000a,00000024): returning
0x40395c08
Finished the memory games

gcc linux native: pointeraddress on 'one' and 'three' are the same.
MS Windows (bcc): pointeraddress on 'one' and 'three' are the same.
Wine            : pointeraddress on 'one' and 'three' differ OR
malloc('three') failes.
                  this depends on the size of the allocated memory.




 zero : 0x40870020
 one  : 0x53480020
 two  : 0x66090020

 three: 0
------------------------------------------------------------------

Hope you can help me with this.

By the way, i get the same problems when compiling my testcase against
winelib.

Johannes Holzer

P.S.: gcc 3.3.5 with Linux (native!) gives me the same results like
windows.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hl_testcase.cpp
Type: text/x-c++src
Size: 2464 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-users/attachments/20060628/1f787327/hl_testcase-0001.cpp
-------------- next part --------------
Allocating 3x 300 MB Virtual Memory...
Freeing middle piece of memory..
Allocating same size again..
Finished the memory games

gcc linux native: pointeraddress on 'one' and 'three' are the same.
MS Windows (bcc): pointeraddress on 'one' and 'three' are the same.
Wine            : pointeraddress on 'one' and 'three' differ OR malloc('three')
failes.
                  this depends on the size of the allocated memory.




 zero : 1c20004
 one  : 14830004
 two  : 32770004

 three: 14830004

Please type in a number and press return to quit:
-------------- next part --------------
Allocating 3x 300 MB Virtual Memory...
Freeing middle piece of memory..
Allocating same size again..
Finished the memory games

gcc linux native: pointeraddress on 'one' and 'three' are the same.
MS Windows (bcc): pointeraddress on 'one' and 'three' are the same.
Wine            : pointeraddress on 'one' and 'three' differ OR malloc('three') failes.
                  this depends on the size of the allocated memory.




 zero : 0x40870020
 one  : 0x53480020
 two  : 0x66090020

 three: 0

Please type in a number and press return to quit: 


More information about the wine-users mailing list