Memory allocation problems with -mthreads flag

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Memory allocation problems with -mthreads flag

Alexander Kalinin
Hello!

I have the following test:

-- main.cpp ---------------------------------------------------------
#include <iostream>
#include <malloc.h>

void VoxelView()
{
    static const int count = 398500000;
   
    char* buf1 = new char[count];
    if(!buf1)
    {
        std::cout << count << " bytes malloc fail!\n";
    }
   
    char* buf2 = new char[count];
    if(!buf2)
    {
        std::cout << count << " bytes malloc fail!\n";
    }
   
    delete[] buf1;
    delete[] buf2;
}

void MemoryFragmentation()
{
    static const int count = 10000;
    int* strings[count];
    for (int i = 0; i < count; ++i)
    {
        strings[i] = new int[15000];
    }
    for (int i = 0; i < count; ++i)
    {
        delete[] strings[i];
    }
   
}

int main(int argc, char *argv[])
{
    std::cout << "1 malloc\n";
    VoxelView();
   
    std::cout << "1 memory fragmentation\n";
    MemoryFragmentation();
       
    std::cout << "2 malloc\n";
    VoxelView();
   
    std::cout << "2 memory fragmentation\n";
    MemoryFragmentation();
   
    std::cout << "3 malloc\n";
    VoxelView();
   
    return 0;
}
-------------------------------------------------------------

1. When this program is compiled with command

> g++ main.cpp

it successfully runs.


2. But when this program is compiled with command

g++ -mthreads main.cpp

it is crushed with bad alloc error.


But I need the -mthreads flags. Is there any workarounds about this problem?


System configuration:
OS: Windows XP
Memory: 4G
MinGW version: 3.4.2


--
WBR,
Alexander Kalinin


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
MinGW-users mailing list
[hidden email]

You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users

This list observes the Etiquette found at http://www.mingw.org/Mailing_Lists. We ask that you be polite and do the same.