473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

malloc beyond 20MB fails. Why so limited?

Hi Guru,

I need some data cache (which I want is able to keep tens of thousands
entries) containing DB data in my Unix running process. Each cache
entry is around 0.5k bytes. So, I want to create the Cache area in my
Unix process when the process starts up.
To the contrary to my expectation, once malloc(0.5k) is called
beyond 4000 times, then, trailing malloc() continues to fail.

Isn't it the heap space should be much bigger than 20MB in a Unix
process ?
Why malloc is failing at not big size allocation ?
Any workaround or advice?
thanks

Dec 30 '07 #1
8 2070
<it********@gmail.comwrote in message
I need some data cache (which I want is able to keep tens of thousands
entries) containing DB data in my Unix running process. Each cache
entry is around 0.5k bytes. So, I want to create the Cache area in my
Unix process when the process starts up.
To the contrary to my expectation, once malloc(0.5k) is called
beyond 4000 times, then, trailing malloc() continues to fail.

Isn't it the heap space should be much bigger than 20MB in a Unix
process ?
Why malloc is failing at not big size allocation ?
Any workaround or advice?

Firstly check everything else using a program monitor to make sure you don't
have a hog running simultaneously.
You should have much more than 20MB. Either you are passing the wrong size,
or there is a leak somewhere. Blocks of 500 bytes or so are rather
inefficient, but not that inefficient.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Dec 30 '07 #2
On Dec 30, 12:30 pm, itsolut...@gmail.com wrote:
Hi Guru,

I need some data cache (which I want is able to keep tens of thousands
entries) containing DB data in my Unix running process. Each cache
entry is around 0.5k bytes. So, I want to create the Cache area in my
Unix process when the process starts up.
To the contrary to my expectation, once malloc(0.5k) is called
beyond 4000 times, then, trailing malloc() continues to fail.

Isn't it the heap space should be much bigger than 20MB in a Unix
process ?
Why malloc is failing at not big size allocation ?
Any workaround or advice?
try <news:comp.unix.programmer>
As far as ISO C is concerned, malloc can allocate from 1 to SIZE_MAX.
Dec 30 '07 #3
it********@gmail.com wrote:
Hi Guru,

I need some data cache (which I want is able to keep tens of thousands
entries) containing DB data in my Unix running process. Each cache
entry is around 0.5k bytes. So, I want to create the Cache area in my
Unix process when the process starts up.
To the contrary to my expectation, once malloc(0.5k) is called
beyond 4000 times, then, trailing malloc() continues to fail.

Isn't it the heap space should be much bigger than 20MB in a Unix
process ?
Why malloc is failing at not big size allocation ?
Any workaround or advice?
thanks
Besides checking what Mr McLean told you, check the permissions.
(ulimit). Sometimes administrators limit what a user process can
allocate.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Dec 30 '07 #4
jacob navia wrote:
All that is true but the user is running in a Unix system, that
is unlikely to have such a bad malloc implementation...
I wouldn't be so sure about this. Some Unix libc have been
developed for speed and simplicity, at the sacrifice of memory
efficiency.

Wolfgang Draxinger
--
E-Mail address works, Jabber: he******@jabber.org, ICQ: 134682867

Dec 30 '07 #5
The issue I have encountered occurs in a network device running BSD.
malloc(1024 * 20000) is ok but malloc(1024 * 30000) always fails.
Looks like due to ulimit issue or similar limit ... right?
Follow-up question (to overcome that limitation)

When implementing a memory pool of having 30MB or so,
using global static memory instead of using heap is the better
way ?
thanks

On Dec 30, 2:30 am, itsolut...@gmail.com wrote:
Hi Guru,

I need some data cache (which I want is able to keep tens of thousands
entries) containing DB data in my Unix running process. Each cache
entry is around 0.5k bytes. So, I want to create the Cache area in my
Unix process when the process starts up.
To the contrary to my expectation, once malloc(0.5k) is called
beyond 4000 times, then, trailing malloc() continues to fail.

Isn't it the heap space should be much bigger than 20MB in a Unix
process ?
Why malloc is failing at not big size allocation ?
Any workaround or advice?

thanks
Dec 30 '07 #6
On Sun, 30 Dec 2007 05:35:36 -0600, jacob navia wrote
(in article <fl**********@aioe.org>):
it********@gmail.com wrote:
>Hi Guru,

I need some data cache (which I want is able to keep tens of thousands
entries) containing DB data in my Unix running process. Each cache
entry is around 0.5k bytes. So, I want to create the Cache area in my
Unix process when the process starts up.
To the contrary to my expectation, once malloc(0.5k) is called
beyond 4000 times, then, trailing malloc() continues to fail.

Isn't it the heap space should be much bigger than 20MB in a Unix
process ?
Why malloc is failing at not big size allocation ?
Any workaround or advice?
thanks

Besides checking what Mr McLean told you, check the permissions.
(ulimit). Sometimes administrators limit what a user process can
allocate.
Yes, and there are also per-process limits, for example 2GB for a
32-bit Linux system is common, which you might be bumping up against
due to the size of other code and data in the process, or by an
unintentional memory leak, the inclusion of a bloatware library, there
could be a lot of potential reasons. You can /usually/ grab via malloc
something quite close to 2GB with a single malloc() call in small apps,
somewhere in the 1700MB range wouldn't surprise me at all.

However, none of this is really a standard C issue, and more an issue
with a particular platform/system setup, or an undetected error in the
code. Taking it up in a forum dedicated to your platform would make a
lot more sense.

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Dec 30 '07 #7

<it********@gmail.comschreef in bericht
news:12**********************************@s19g2000 prg.googlegroups.com...
Hi Guru,

I need some data cache (which I want is able to keep tens of thousands
entries) containing DB data in my Unix running process. Each cache
entry is around 0.5k bytes. So, I want to create the Cache area in my
Unix process when the process starts up.
To the contrary to my expectation, once malloc(0.5k) is called
beyond 4000 times, then, trailing malloc() continues to fail.

Isn't it the heap space should be much bigger than 20MB in a Unix
process ?
Why malloc is failing at not big size allocation ?
Any workaround or advice?
If you know you will call malloc 4k times with 512 bytes (that is 2MB by the
way) why not call malloc once with that size and create a function to return
a pointer to the next 512 bytes at every call. This way all that memory will
be contiguous in memory
>

thanks
Dec 30 '07 #8
# Isn't it the heap space should be much bigger than 20MB in a Unix
# process ?

No.

Yes.

No.

Depends. Are there resource limits? Do you have manually add
sectors to VM on your unix? Is your boot drive track limitting?

# Why malloc is failing at not big size allocation ?

Is that what the errno is saying?

# Any workaround or advice?

Many unices have performance tools that help you figure out
if you're exhausting VM, but it depends on which unix you've
got.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Wow. A sailboat.
Jan 1 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Bren | last post by:
Can anybody tell me what is wrong with this code? void SystemModule::AddModuleDependency(PTR_MODULE_INFO pModuleInfo) { if (!pModuleInfo) return; PTR_MODULE_INFO pDest = 0; if...
4
by: afarah | last post by:
Under what condition will we see a segmentation fault in the malloc library routine? Specifically, a failure in call to "chunk_alloc()" from within malloc. I have a multi-threaded c++ program...
11
by: Sushil | last post by:
Hi Gurus I've tried to come up with a small logical example of my problem. The problem is platform specific (MIPS) which I understand should not be discussed here. So here goes my example: ...
25
by: H.A. Sujith | last post by:
If malloc fails what should I do? 1. Exit imediately. 2. Print an error message (or put a log entry) and exit. 3. Print an error message (or put a log entry) and continue execution (after...
6
by: Maja | last post by:
Greetings, /var/adm/wtmp files were getting out of hand and I wanted to filter the file rather than zeroing it out. I found some code that would only keep the last x days but it required...
12
by: gooch | last post by:
I originally posted the following code in a group discussing threads but after further research I think I have a c question about the code. I know there are a couple of non standard c includes here...
11
by: subramanian | last post by:
Suppose int size = INT_MAX / 8; char a; are declared to use the feature of variable lenght array(VLA) in C99. With appropriate #includes, when this code is run, segmentation fault occurs in Red...
6
by: itsolution | last post by:
Hi folks, Could you shed some light on this issue? my program is running on Freebsd as a daemon. When user sends a request, it forks itself and lets its child process handles the request....
173
by: Marty James | last post by:
Howdy, I was reflecting recently on malloc. Obviously, for tiny allocations like 20 bytes to strcpy a filename or something, there's no point putting in a check on the return value of malloc....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.