Jump to content
  • Advertisement
Sign in to follow this  
b1gjo3

insufficient memory??

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

Hi, this problem has me pulling my hair out. sdb->files = (save_bin_file*)malloc(sizeof(save_bin_file)*sdb->info.num_files); returns a null pointer and the errno is ENOMEM. When i look at my memory management i have like 3.2gb free, and its allocating less than a kb. why is it having this behavior? thanks

Share this post


Link to post
Share on other sites
Advertisement
Sometimes heap corruption can be reported as insufficient memory. Double check for buffer overflows and other similar problems.

Share this post


Link to post
Share on other sites
ok so i learned that this only happens when i step through the debugger in vc++, when its the debug build (it didnt used to do this). when i step through the debugger in the release build... its works like intended...

why would this be? i dont see any room for any buffer overflows as well

Share this post


Link to post
Share on other sites
Variables can sometimes have different initial values in debug and release modes, so check to ensure that everything is properly initialized.

Share this post


Link to post
Share on other sites
I tried initializing my pointers to NULL before allocating but that doesnt do anything.

This is what I get in my output window after malloc

First-chance exception at 0x77a22c07 in save parser.exe: 0xC0000005: Access violation reading location 0xfdfdfdfd.

Why does it do this?

Share this post


Link to post
Share on other sites
0xFDFDFDFD is the bit pattern the debug version of the MSVC's C runtime uses to fill the area before and after a memory allocation. Seeing an access of that location generally means that you're indexing a memory block out of bounds.

Share this post


Link to post
Share on other sites
ok ive fixed it but im not clear on why this works...

i have two structs of importance here, a save_data_bin, and save_data_file


typedef struct save_bin_file
{
u8 file_header[0x80];
u32 file_size;
u8 perm, attr, type;
u8* file_name;
u8* file_data;
}save_data_file;

typedef struct save_data_bin
{
u8 header[0xf0c0];
save_bin_info info;
save_bin_file* files;
}save_data_bin;



in my main function i allocate a save_data_bin on the stack. I pass this variable by reference to this function

bool read_bin_files(FILE* fp, save_data_bin* sdb)

and its here where i malloc sdb->files and it fails.

When i malloc save_data_bin in my main function on the heap, it works fine.
Why is this now?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!