Jump to content
  • Advertisement
Sign in to follow this  
Sabonis

allocating memory for arrays

This topic is 4756 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

hey guys, I'm writing a program in C that will fill in an allocated array of doubles... My question is: What is the right way to allocate memory for an array of doubles with malloc()? double *input; input = (double*)malloc(sizeof(double)*num_elements); is what i have so far... doesnt seem to work. Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by SiCrane
What do you mean by "doesn't seem to work"?


... as in when I try to access the elements my program crashes

Share this post


Link to post
Share on other sites
Is the return value from malloc() 0? If so you might have heap corruption somewhere else in your program, or num_elements could be too big.

Share this post


Link to post
Share on other sites
i would like to know if this is proper way to allocate an array of doubles in the free store? or are there other ways?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!