Sponsored Content
Top Forums Programming allocate memory for the same struct: sometimes successful, sometimes failure, why Post 302267726 by shamrock on Saturday 13th of December 2008 03:58:32 PM
Old 12-13-2008
Quote:
Originally Posted by cdbug
Trouble does not lie in the declaration. It is correct.
but the statement can not execute sometimes, especially in functions or when creating a large array

Are there some skills which help avoid such failures? I can not understand why it occurs and have no way to deal with it.
The best skill is to check the return value from malloc if it's NULL then exit the program. If you don't do this your program will generate a SIGSEGV fault and crash. Fixes include increasing the size of the data segment via the maxdsize kernel parameter but even this is not foolproof as seen when mallocing a very large array and as Franklin52 said about freeing what had been malloced before and is not needed now before mallocing a new chunk of memory.
 

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. 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

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. 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

9. 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

10. Programming

calloc fails: 'Cannot allocate memory'

Hi , experts. I work on Linux station (RedHat 5.7), regular user, but have root password. %> uname -a Linux ran1log06 2.6.18-238.1.1.el5 #1 SMP Tue Jan 4 13:32:19 EST 2011 x86_64 x86_64 x86_64 GNU/Linux %> cat /etc/issue Red Hat Enterprise Linux Client release 5.7 (Tikanga) Kernel \r on... (5 Replies)
Discussion started by: baruchgu
5 Replies
pcsample(2)							   System Calls 						       pcsample(2)

NAME
pcsample - program execution time profile SYNOPSIS
#include <pcsample.h> long pcsample(uintptr_t samples[], long nsamples); DESCRIPTION
The pcsample() function provides CPU-use statistics by profiling the amount of CPU time expended by a program. For profiling dynamically-linked programs and 64-bit programs, it is superior to the profil(2) function, which assumes that the entire pro- gram is contained in a small, contiguous segment of the address space, divides this segment into "bins", and on each clock tick increments the counter in the bin where the program is currently executing. With shared libraries creating discontinuous program segments spread throughout the address space, and with 64-bit address spaces so large that the size of "bins" would be measured in megabytes, the profil() function is of limited value. The pcsample() function is passed an array samples containing nsamples pointer-sized elements. During program execution, the kernel samples the program counter of the process, storing unadulterated values in the array on each clock tick. The kernel stops writing to the array when it is full, which occurs after nsamples / HZ seconds of process virtual time. The HZ value is obtained by invoking the call sysconf(_SC_CLK_TCK). See sysconf(3C). The sampling can be stopped by a subsequent call to pcsample() with the nsamples argument set to 0. Like profil(), sampling continues across a call to fork(2), but is disabled by a call to one of the exec family of functions (see exec(2)). It is also disabled if an update of the samples[] array causes a memory fault. RETURN VALUES
The pcsample() function always returns 0 the first time it is called. On subsequent calls, it returns the number of samples that were stored during the previous invocation. If nsamples is invalid, it returns -1 and sets errno to indicate the error. ERRORS
The pcsample() function will fail if: EINVAL The value of nsamples is not valid. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Async-Signal-Safe | +-----------------------------+-----------------------------+ |Interface Stability |Stable | +-----------------------------+-----------------------------+ SEE ALSO
exec(2), fork(2), profil(2), sysconf(3C), attributes(5) SunOS 5.10 10 Mar 1998 pcsample(2)
All times are GMT -4. The time now is 09:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy