Sign in to follow this  

insufficient memory??

This topic is 3293 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
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
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
You might really be running out of memory. The default stack size, at least in MSVC and some other compilers I've used, isn't very large. Usually only 1MB or so. How big is 'save_bin_info'?

If you're using MSVC, go to Project->Properties->Configuration Properties::Linker::System, and see what your Stack and Heap sizes are. Most likely they're set to default via a value of '0'. Trying setting them to a value larger than the default (which I *think* is 1MB). See if that fixes your problem.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mantear
You might really be running out of memory. The default stack size, at least in MSVC and some other compilers I've used, isn't very large. Usually only 1MB or so. How big is 'save_bin_info'?

If you're using MSVC, go to Project->Properties->Configuration Properties::Linker::System, and see what your Stack and Heap sizes are. Most likely they're set to default via a value of '0'. Trying setting them to a value larger than the default (which I *think* is 1MB). See if that fixes your problem.


works excellent, the values were at 0, changed them and works like a charm. thanks all

Share this post


Link to post
Share on other sites

This topic is 3293 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this