Hi All,
I have a class that tries to allocate memory dynamically after
doing some processing in a member variable. The class contains:
2 integers,
2 char[256];
and 1 char* ptr;
This "ptr" would be allocated later on when I get hold of a valid
input.
During initial Creation of the objects, things go through fine. I am
able to allocate memory dynamically for this class. sizeof(myclass)
turns out to be around 1040 bytes.
But after 2 runs, the third time when I try to allocate a new instance
by calling "new myclass()" - it just fails with a Segmentation. The same
code goes through fine the first 2 times. I am afraid I might have
corrupted the malloc/new memory management scheme. If I actually remove
the "ptr" as a member variable of the class, it works fine any number of
times. I tried to allocate using malloc which also failed at the same
point.
cout << "Size of mapping is " << sizeof(mapping) << endl;
void* ptr1 = malloc(sizeof(mapping)); ------> fails
//void* ptr1 = valloc(1040);
------> fails
cout << " allocated memory\n";
cout.flush();
ptr = new mapping(resourceName, 0, this->count); ------> fails
Can somebody provide help on this?
thanks in advance,
Sabha