Hi,

I am getting the following error :

test.o(11488) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
test.o(11488) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
test.o(11488) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
test.o(11488) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
terminate called recursively
Abort trap

I am using finite recursion to build the nodes of binary tree. So i believe the C++ program should take care of the storage of nodes. I also think that it will store the nodes of the binary tree in a heap.

Please help

Thanks

Umm, your code?

Umm, your code?

Exactly my thoughts.

From what I understand, malloc can fail if you've run out of heap-space your program is using for dynamic allocation or if you are attempting to allocate memory to a location that is in use by another process. size=2097152 Your heap should be (by default) 512 MB, which is (depending on how "Mega" and "Kilo" are interpreted) 1024 * 512 Kilobytes and 1024 * 1024 * 512 bytes.

So you should have enough space (by default, not saying this isn't expandable), but the question is what object (or hopefully struct) are you trying to allocate memory for using a C-style mem allocator? I believe some structures have a limit on the amount of memory they can hold, but a professional would have to confirm that.

Hi,

I am pasting part of the code ... recursion part. It is big code so i am not sure whether teh code will help or not. 


int circuit::f1(int out_g)
{
	/* Initially the output of the gate is don't care. This is 
	only true for the first time when the function is called */
	
	int outg = out_g;
	
	/* If output is excited to '1' return true */
	if(output[outg-1][1] == 1)
	{
		status1 = true;
		return status1;
	}
	
	/* If Conflict occurs return false */ 
	if((output[outg-1][1] != 1) && (output[outg-1][1] != 2)) 
	{
		number_backtrack++;
		status1 = false;
		return status1;
	}
		
	int kgg = 0;
	number_backtrace++;
	
	kgg = backtrace(outgate,1);
	
	solve(input_column[kgg][0],input_column[kgg][1]);
	if(f1(outg) == true)
	{
	    status1 = true;
	    return status1;
	}
	
	if(input_column[kgg][1] == 1)
		input_column[kgg][1] = 0;
	else if(input_column[kgg][1] == 0)
		input_column[kgg][1] = 1;
	solve(input_column[kgg][0],input_column[kgg][1]);
	
	if(f1(outg) == true)
	{
		status1 = true;
		return status1;
	}
	
	input_column[kgg][1] = 2;
	solve(input_column[kgg][0],input_column[kgg][1]);
	
	
	status1 = false;
	return status1;
	
	fprintf(stderr,"\n I am here A");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.