Operating System - HP-UX
1830935 Members
2272 Online
110017 Solutions
New Discussion

Re: problem in memory allocation

 
SOLVED
Go to solution
remer
Advisor

problem in memory allocation

hi,

our developer is trying to run a program that needs a memory allocation on its initialization upon running we encoutered this error.

"attempting to initialize 1073741824 bytes of memory failed! Not enough space"

any kernel tunables i need to adjust/change?

thanks.
7 REPLIES 7
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: problem in memory allocation

Have a look at maxdsiz (the 32-bit limit) and it's 64-bit cousin, maxdsiz_64bit. If this is 32-bit code, you need to enable more than a 1 quadrant data segment.

You could also be hitting ulimit or (more rarely a lack of swap space). Any of these can cause malloc() or its relatives to set errno = ENOMEM but I'm betting that you are either hitting maxdsiz or a quadrant.
If it ain't broke, I can fix that.
remer
Advisor

Re: problem in memory allocation

here's the value:

maxdsiz 1073741824 Default Immed
maxdsiz_64bit 4294967296 Default Immed

so i need to change the value of maxdsiz into 2147483648? how about the maxdsiz_64bit what value will better?

thanks.
A. Clay Stephenson
Acclaimed Contributor

Re: problem in memory allocation

Having maxdsiz_64bit set to 4GiB is a reasonable value unless you have a process that actually needs more.

One thing to be aware of is (especially in 32-bit code) is that the stack and data segments are allocated from the same quadrant by default. This means that if you set maxssiz to 256MiB, for example, that the amount of space that can be allocated is decreased by 256MiB regardless of whether the run-time stack ever approaches the 256MiB value. A reasonable value for maxssiz is 32MiB and 128MiB for maxssiz_64bit. These are extremely generourous as only poorly written code would ever need stacks larger than this.

If there is a choice, have your developer compile/link this code as 64-bit and essentially all of these limits disappear.
If it ain't broke, I can fix that.
remer
Advisor

Re: problem in memory allocation

is there a way the developer can compile as a 64-bit?

here is the code. hope this will help.

int main( int argc, char **argv )

{

void * mem_space = NULL;

int mem_size = 0;





mem_size = atoi(argv[1]);





mem_space = ( void * ) malloc( mem_size );



if( mem_space == NULL )

{

printf( "attempting to initialize %d bytes of memory failed! %s\n", mem_size, strerror( errno ) );

exit( 1 );

}

else

{

printf( "attempting to initialize %d bytes of memory successful!\n", mem_size );

free( mem_space );

exit( 0 );

}



}
A. Clay Stephenson
Acclaimed Contributor

Re: problem in memory allocation

First, hit your developer over the head with a baseball bat for not using header files like stdlib.h and unistd.h because the default casting of functions and their arguments is a sure-fire way to clobber 32 to 64 bit conversions.

I have no idea how to tell you how to enable 64-bit code because you haven't bothered to identify your compiler. It really doesn't matter because you should be asking the box rather than some idiot on the Internet anyway. Do a man gcc or man aCC or whatever and it should be obvious what compiler flags are needed (e.g. +DD64).
If it ain't broke, I can fix that.
remer
Advisor

Re: problem in memory allocation

thanks i get it.
Dennis Handly
Acclaimed Contributor

Re: problem in memory allocation

>is there a way the developer can compile as a 64-bit?

As Clay said, you need and +DD64.
And to make Clay happy, if you don't have a prototype for the heap functions, A.06.15 has made it a hard error in 64 bit mode:
error #4313-D: no prototype or definition in scope for call to memory allocation routine "malloc"