Operating System - Linux
1753460 Members
4883 Online
108794 Solutions
New Discussion юеВ

Re: A simple C++ program crashing on HP machine.

 
SOLVED
Go to solution
Don Raman
Advisor

Re: A simple C++ program crashing on HP machine.

By the way, I found one more workaround. When I use a combination of malloc with placement new it does work.

Please see the program below which works:

#include
#include
#include
using namespace std;
class B
{
int abc;
public:
virtual void seti( int aaa) {abc = aaa;}
};

class A : public B
{
int i;
public:
void seti(int a) { i=a; }
int geti() { return i; }
};

int main()
{
long i = 0;
for (i=0; i<=80000000; i++)
{
//A* ptr = new A();
void* space = malloc(sizeof(A));
A* ptr = new(space) A();
}
return 0;
}

The above program also worked fine without any option.

Regards,
Don.
Ermin Borovac
Honored Contributor
Solution

Re: A simple C++ program crashing on HP machine.

32-bit process memory space is divided into 4 quadrants, each quadrant being 1G in size.

Malloced space goes into 2nd quadrant, so by default you can allocate maximum of 1G (even if maxdsiz is greater than 1G).

Process stack also goes into 2nd quadrant. Stack space is reserved with maxssiz, which means that large maxssiz will reduce amount that can be malloced. There are some other areas in 2nd quadrant and that will reduce amount that can be malloced even further.

With -N option amount of memory that can be allocated by malloc is expanded into 1st quadrant (which normally contains process text).

This can further be expanded to 3rd and 4th quadrant by chatr (+q3p and +q4p).

Don Raman
Advisor

Re: A simple C++ program crashing on HP machine.

I tried -N option but now the tool crashes with bus error. Analyzed it with gdb and got the same traceback.

Can you tell the exact usage of chatr?

Regards,
Don.
Don Raman
Advisor

Re: A simple C++ program crashing on HP machine.

I got the usage. Again the test program is working fine. let me see the actual prgram.

Regards,
Don.
Don Raman
Advisor

Re: A simple C++ program crashing on HP machine.

My tool was already having -N option. But when I used +q3p it did work. Thanks a lot.

Again I would like to thank everyone involved here. You people are great!!!

Regards,
Don.
Don Raman
Advisor

Re: A simple C++ program crashing on HP machine.

Thanks everyone for all the help and support.