malloc() return value and available memory...

Started by
2 comments, last by grbrg 21 years, 1 month ago
I''m having this problem with allocating memory (with malloc) for a new variable: it returns NULL (meaning no memory available). What I don''t understand about this is, there should be enough memory available! I can define 100 non-dynamic variables of the same type (a structure) without a problem (was just for testing) and the system resource tells me there''s plenty left! So, could a NULL mean something different than "no memory available"? Or does malloc have a different address room than non-dynamic variables...? Or what else could be the problem? Thanks for your help! PS: I HAD to do this in C... ^^ ------------------------------ "Reality is nothing, perception is everything!" - First Wizard Zeddicus Zu''l Zorander

------------------------------

There are only 10 kinds of people: those that understand binary and those that don't.

Advertisement
How much memory (in bytes) are you requesting??

Returning a NULL means it cant allocate a block of that size.
You may have enought memory but it may be fragmented all over the place.

It also my be your OS not letting you have the memory.
there might be some limit to how much a single process can have.

Question: "I HAD to do this in C" ? mening what exactly.
Most launguages have a malloc of some description.


Armand.
Armand -------------------------It is a good day to code.
The structure is only 8 bytes... and I can include 100 variables of the same structure if they are non-dynamic!

I worked with C++, Java, C# - pure C is a shock coming from OO.

------------------------------
"Reality is nothing, perception is everything!" - First Wizard Zeddicus Zu''l Zorander

------------------------------

There are only 10 kinds of people: those that understand binary and those that don't.

[grbrg] Can you put source, how You allocate memory using malloc ?

[edited by - Estor on March 6, 2003 8:00:28 AM]
"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We WouldWhen Losers Say Its Over With You Know That It's A Lie The Gods Made Heavy Metal And It's Never Gonna Die"THE GODS MADE HEAVY METAL/by ManOwaR

This topic is closed to new replies.

Advertisement