HPX memory calloc error - returns NULL

P

pervinder

Hi,
I have a c applicaiton which uses calloc to allocate the storage from
heap.
A page is allocated (4096bytes) and then its used in smal small chunks
on need.

It works fine till some n number of pages are alloacted and used. But
it fails
to allocate a fresh page of 4096 after some m times when the prev.
block gets exhausted and new block needs to be allocated/reserved.

result = (alloc_list *) calloc((size_t) ASIZE, 1));
The result becomes NULL... (ASIZE is 4096)
Ran purify and it gave a MAF (Memory allocation Failure)

Any hints as how to go about this issue ?

I have a hp machine with limit as :-
$::home> limit
cputime 0:0-1
filesize 4194303 kbytes
datasize 2883584 kbytes
stacksize 262144 kbytes
coredumpsize 0 kbytes
memoryuse 4194303 kbytes
descriptors 200

Regards, ~Pervinder
 
J

Jens.Toerring

pervinder said:
I have a c applicaiton which uses calloc to allocate the storage from
heap.
A page is allocated (4096bytes) and then its used in smal small chunks
on need.
It works fine till some n number of pages are alloacted and used. But
it fails
to allocate a fresh page of 4096 after some m times when the prev.
block gets exhausted and new block needs to be allocated/reserved.
result = (alloc_list *) calloc((size_t) ASIZE, 1));

Casting the return value of (c|m|re)alloc() is superfluous and
only will keep the compiler from complaining if you forgot to
include said:
The result becomes NULL... (ASIZE is 4096)

calloc() (or malloc() or realloc()) returning NULL is completely
legitimate - it means the system can't or won't give you anymore
memory. Why it won't give you more depends on lots of system
specific stuff - you may have reached some system-imposed limits,
limits set for your processes, or you may already be using up all
memory there is etc. - so you will have to ask in a group dedicated
to your system or perhaps comp.unix.programmer.
I have a hp machine with limit as :-
$::home> limit
cputime 0:0-1
filesize 4194303 kbytes
datasize 2883584 kbytes
stacksize 262144 kbytes
coredumpsize 0 kbytes
memoryuse 4194303 kbytes
descriptors 200

But even there your printout of the limits will be useless unless
you also tell after how many allocations it fails - if 'datasize'
stands for the upper limit of memory your program is allowed to
use it wouldn't be a surprise if calloc() fails after about 720,000
allocations, but things would probably be different if it fails
after only say 5 (assuming that you really have several GB of
(virtual) memory and the above numbers aren't due to an unrea-
sonable setting of the limits).
Regards, Jens
 
J

Jack Klein

Casting the return value of (c|m|re)alloc() is superfluous and
only will keep the compiler from complaining if you forgot to
include <stdlib.h>.

....as is casting either of the arguments to size_t. In this
particular case, if there is no prototype in scope, casting ASIZE to
size_t is particularly useless, as the literal 1 will be passed as an
int. And an int cannot possible be a size_t.
 
P

pervinder

The 'n' is large but total memory allocated till the failure
instant using calloc and malloc calls is ~250 Mb and the
peak memory usage reported byt the executable after
failure is 733 Mb

Since the system has enogh memory (maxdsize 3G) so i
think the issue here is not the memory allocation but its
somewhat different. May be some hp system specific
seting are limiting the same..
-Pervinder
 
P

pervinder

The issue looks more of a hpx system imposed limits.
I tried to allocate chunks of 128Kb till program runs out of memory
And when i run the code on hpux, it goes out of memory after
allocating a 767Mb from heap..
-Pervinder
 
P

pervinder

I used chatr and executable worked fine
$ chatr +q3p enable <ExeName>
Please comment...
-Pervinder
 
J

Jens.Toerring

pervinder said:
I used chatr and executable worked fine
$ chatr +q3p enable <ExeName>
Please comment...

No, not here since that has nothing to do with C - and you're
posting to comp.lang.c and not comp.solving.hp.ux.problems or
whatever. Go to a group where this is on-topic.

Regards, Jens
 
C

CBFalconer

pervinder said:
I used chatr and executable worked fine
$ chatr +q3p enable <ExeName>
Please comment...

Allright. I have no idea what a chatr is, nor the vaguest idea
what, if anything, you are talking about. With the total lack of
context it could be anything. However I highly suspect it is
off-topic here. I suggest you learn how to use newsgroups.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top