memory allocation with new under linux
From: arju (arvydas.juskaitis_at_mogul.com)
Date: 08/11/05
- Previous message: Paul Pluzhnikov: "Re: GDB gets lost in the routine referneced by pthread_create()"
- Next in thread: Kasper Dupont: "Re: memory allocation with new under linux"
- Reply: Kasper Dupont: "Re: memory allocation with new under linux"
- Reply: David Schwartz: "Re: memory allocation with new under linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Aug 2005 08:32:31 -0700
Hi,
I'm developing a C++ program under Linux, which allocates lots of
memory and fails sometimes - system sends KILL or TERM signal.
I wrote a small program to test mem allocation and it fails in the same
way.
If I allocate bigger chunks of memory (250MB), operator new throws
bad_alloc exception, as it is expected.
#include <stdio.h>
#include <stdlib.h>
#include <string>
int main()
{
unsigned long size = 0x100000;
unsigned long count = 0xffffffff / size;
try {
for(int i = 0; i < count; i++) {
printf("#%d ", i);
char* ptr = new char[size];
printf("new ");
memset(ptr, 0, size);
printf("memset\n");
}
} catch(std::bad_alloc& e) {
printf("catch\n");
}
printf("done\n");
return 0;
}
So the problem is - it shouldn't crash, program should receive
exception instead.
I'm running Suse 9.2 as development platform.
Thanks,
Arvid
- Previous message: Paul Pluzhnikov: "Re: GDB gets lost in the routine referneced by pthread_create()"
- Next in thread: Kasper Dupont: "Re: memory allocation with new under linux"
- Reply: Kasper Dupont: "Re: memory allocation with new under linux"
- Reply: David Schwartz: "Re: memory allocation with new under linux"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|