Re: Re: malloc small pieces of memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
//---------------------------------------------------------------------------

#pragma hdrstop
#include <iostream>
//---------------------------------------------------------------------------
using namespace std;
typedef unsigned int            ui32;                   // Kuerzel: ui32

#define MBYTE 1024*1024

/* Windows: 400MB works
 * Linux  : 400MB works (gcc 3.3.5 for Linux (native))
 * wine   : 200MB: seems to work okay, but pointer 'one' != pointer 'three') 
 *          300MB: fourth malloc ('three') failes
 *          400MB: third malloc failes, fourth malloc works again. 
 */
#define MEM 300*MBYTE 

#pragma argsused
int main(int argc, char* argv[])
{
        unsigned int *pointerarray;
        unsigned int *pointerarray1;
        unsigned int *pointerarray2;
        unsigned int *pointerarray3;

        cout << "Allocating 3x "<< MEM/1024/1024 <<  " MB Virtual Memory..." << endl;
        pointerarray = (unsigned int *) malloc(MEM);       /* 'zero' */
        pointerarray1 = (unsigned int *) malloc(MEM);      /* 'one'  */
        pointerarray2 = (unsigned int *) malloc(MEM);      /* 'two'  */
        cout << "Freeing middle piece of memory.." << endl;
        free((unsigned int *) pointerarray1);
        cout << "Allocating same size again.." << endl;
        pointerarray3 = (unsigned int *) malloc(MEM);    /* 'four' */
        cout << "Finished the memory games" << endl;

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

        cout << hex << " zero : " << pointerarray << endl
             << " one  : " << pointerarray1 << endl
             << " two  : " << pointerarray2 << endl << endl
             << " three: " << pointerarray3 << endl << endl;

        cout << "Please type in a number and press return to quit: ";
        int i;
        cin >> i;

        free(pointerarray);
//      free(pointerarray1);
        free(pointerarray2);
        free(pointerarray3);
        exit(0);
}
//---------------------------------------------------------------------------

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:
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: 
_______________________________________________
wine-users mailing list
wine-users@xxxxxxxxxx
http://www.winehq.org/mailman/listinfo/wine-users

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux