Sponsored Content
Top Forums Programming calloc fails: 'Cannot allocate memory' Post 302600331 by jim mcnamara on Monday 20th of February 2012 10:40:30 PM
Old 02-20-2012
You can fragment memory by making a lots of calls to malloc or calloc, freeing some blocks and keeping others. After a while substantially larger allocation requests fail because there is not enough free contiguous memory.

Based on your free -t output I would say you have a lot of memory. So, my best guess is fragmentation.

As a possible fix, consider adding more (way more) swap, say 50GB.

But - whatever your code does it would appear not to play well with others. Running it on a busy production system could bring that system to its knees. Your code needs help.

Start by debugging your malloc calls (calloc() calls malloc() )
There are good malloc debugging libraries out there for linux for example:
Dmalloc - Debug Malloc Home Page This will show where your problems occur.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix Help - allocate more memory to /tmp

Hi Guys I using Solaris 8 and I need to change the size of my /tmp file. Was wondering does anyone know how to do this. Thanks Carson (1 Reply)
Discussion started by: cmackin
1 Replies

2. Programming

how allocate virtual memory

Hi Folks can any body suggest how to allocate virtual memory any function for that (2 Replies)
Discussion started by: munnu
2 Replies

3. UNIX for Advanced & Expert Users

unable to allocate enough memory

On SunOS 5.8 I get an error when starting a large Java process with over 2Gb memory. Error occurred during initialization of VM Could not reserve enough space for object heap When stopping several other Java processes we can start this process. This seems to indicate that we don't have... (11 Replies)
Discussion started by: rein
11 Replies

4. UNIX for Advanced & Expert Users

How to allocate memory

Hi, I have 2 systems with same hardware and software. One system is giving me error "Error occurred during initialization of VM Could not reserve enough space for object " when I tried to increase JBoss App's heap size to 2GB while the other system is running fine without any issue. Is there... (5 Replies)
Discussion started by: ravi3553
5 Replies

5. UNIX for Advanced & Expert Users

Oracle how many memory allocate really

hi... i want to find oracle allocate how many memory really.. i execute this code to list memory on unix system : ps -eo pmem,args | sort -k 1 -r -n outputs ; %mem command 12.9|ora_smon_RTX 12.9|ora_s000_RTX 12.9|ora_reco_RTX 12.9|ora_qmnc_RTX... (2 Replies)
Discussion started by: utoptas
2 Replies

6. SuSE

shmget failed - cannot allocate memory

Hi, In my proj, one process was running for 2 days. after 2 days its throwing an error message "shmget failed cannot allocate memory". the same problem happened every time.i.e. i can reproduce the same issue if my process is running for every 2 days for a same operation.Within this 2 days there... (1 Reply)
Discussion started by: ManoharanMani
1 Replies

7. Linux

shmget failed - cannot allocate memory

Hi, In my proj, one process was running for 2 days. after 2 days its throwing an error message "shmget failed cannot allocate memory". the same problem happened every time.i.e. i can reproduce the same issue if my process is running for every 2 days for a same operation.Within this 2 days there... (1 Reply)
Discussion started by: ManoharanMani
1 Replies

8. Linux

shmget failed - cannot allocate memory

Hi, In my proj, one process was running for 2 days. after 2 days its throwing an error message "shmget failed cannot allocate memory". the same problem happened every time.i.e. i can reproduce the same issue if my process is running for every 2 days for a same operation.Within this 2 days there... (1 Reply)
Discussion started by: ManoharanMani
1 Replies

9. Programming

How to allocate memory to a string in C?

hi I want to take string as a input from user and the string is very very length. From the lengthy string i have to substring take first 16 letters, then next 8 letters,................... Please guide me how to write program to take lengthy string from user and sub string it. Thanks (4 Replies)
Discussion started by: atharalikhan
4 Replies

10. Solaris

unable to allocate enough memory

On SunOS 10 get an error when starting a large Java process with over 2Gb memory. Error occurred during initialization of VM Could not reserve enough space for object heap i have 32G memory !! , swap = 31G Please any advice !!! (3 Replies)
Discussion started by: moata_u
3 Replies
MALLOC(3)						     Library Functions Manual							 MALLOC(3)

NAME
malloc, free, realloc, calloc, alloca - memory allocator SYNOPSIS
#include <sys/types.h> #include <stdlib.h> #include <alloca.h> void *malloc(size_t size) void free(void *ptr) void *realloc(void *ptr, size_t size) void *calloc(size_t nelem, size_t elsize) void *alloca(size_t size) DESCRIPTION
Malloc and free provide a general-purpose memory allocation package. Malloc returns a pointer to a block of at least size bytes beginning on a word boundary. The argument to free is a pointer to a block previously allocated by malloc; this space is made available for further allocation, but its contents are left undisturbed. A call with a null ptr is legal and does nothing. Needless to say, grave disorder will result if the space assigned by malloc is overrun or if some random number is handed to free. Malloc maintains multiple lists of free blocks according to size, allocating space from the appropriate list. It calls sbrk (see brk(2)) to get more memory from the system when there is no suitable space already free. Realloc changes the size of the block pointed to by ptr to size bytes and returns a pointer to the (possibly moved) block. The contents will be unchanged up to the lesser of the new and old sizes. A call with a null ptr is legal and has the same result as malloc(size). Calloc allocates space for an array of nelem elements of size elsize. The space is initialized to zeros. Alloca allocates size bytes of space in the stack frame of the caller. This temporary space is automatically freed on return. Each of the allocation routines returns a pointer to space suitably aligned (after possible pointer coercion) for storage of any type of object. SEE ALSO
brk(2). DIAGNOSTICS
Malloc, realloc and calloc return a null pointer if there is no available memory or if the arena has been detectably corrupted by storing outside the bounds of a block. NOTES
Other implementations of malloc, realloc or calloc may return a null pointer if the size of the requested block is zero. This implementa- tion will always return a zero length block at a unique address, but you should keep in mind that a null return is possible if the program is run to another system and that this should not be mistakenly seen as an error. BUGS
When realloc returns a null pointer, the block pointed to by ptr may be destroyed. Alloca is machine dependent; its use is discouraged. 4th Berkeley Distribution May 14, 1986 MALLOC(3)
All times are GMT -4. The time now is 02:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy