Jump to content
  • Advertisement

Archived

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

malloc() return value and available memory...

This topic is 5554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!