pervinder <pe*******@gmail.com> wrote:
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 <stdlib.h>.
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
--
\ Jens Thoms Toerring ___
Je***********@physik.fu-berlin.de
\__________________________
http://www.toerring.de