Archived

This topic is now archived and is closed to further replies.

grbrg

malloc() return value and available memory...

Recommended Posts

grbrg    126
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

Share this post


Link to post
Share on other sites
Armand    164
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.

Share this post


Link to post
Share on other sites
grbrg    126
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

Share this post


Link to post
Share on other sites
Estor    127
[grbrg] Can you put source, how You allocate memory using malloc ?

[edited by - Estor on March 6, 2003 8:00:28 AM]

Share this post


Link to post
Share on other sites