Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

malloc not returning anything

Status
Not open for further replies.

infinitetrutles

Electrical
Oct 9, 2006
2
0
0
AU
Hi,

I am having an issue where allocating memory is not returning focus to my code. the call to malloc is made and the processor is running the program at 100%, but my program makes no further progress. is this an infinite loop inside the malloc code?

I currently have the code:

printf("about to allocate %d bytes\n", length);
song[quality] = malloc(length);
printf("malloc completed\n");

when executed this code gets executed a few times inside a loop and things go acording to plan untill i get the output "about to allocate 16 bytes" and then nothing further happens.

I doubt my application has run out of memory as it happens early in the program when not much has been allocated yet, and even then malloc should return an error message. I have also turned off the "enable over commit memory" feature on my computer as i thought maybe that could be the cause.

has anyone seen something simillar before? Thanks,
Dave
 
Replies continue below

Recommended for you

Thanks for the response
song is a 2 dimensional array. so song is an array of pointers (or an array of arrays if you prefer to think of it like that).

for example try compiling the following:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char* example[5];
example[0] = malloc(12);
strcpy(example[0], "hello world\0");
printf(example[0]);
free(example[0]);
return(0);
}

as an update, i have buggered up my memory somewhere as it produces memory errors for a certain input. Hopefully if i track down and debug that this one will simply go away... (fingers crossed)
 
Status
Not open for further replies.

Similar threads

Back
Top