sekxx
22nd November 2003, 19:50
Hello guys,
I want to perform somme malloc in a loop,
here is a sample code:
#include <stdio.h>
typedef struct { char * t;} aBuff;
int main(void)
{
aBuff *t;
int len,i;
len = 1000;
t = (aBuff*)malloc(len);
for (i=0; i<len; i++) {
t[i].t = (char*)malloc(255);
}
// freeing memory here...
system("pause");
return 0;
}
This code is to illustrate my trouble with malloc();
if len = 100, it work,
if len >= 1000, it crash.
I have to do up to 1 000 000 malloc in a loop, for my software (a raster to vector image converter).
So if someone know how to perform a "safe malloc" please tell me ;).
PS:
-- I have enough memory to run my code
-- if I put a lot of code in the loop (to speed down iterations)
it work (but this is not a solution)
Thank's,
SeKxX
I want to perform somme malloc in a loop,
here is a sample code:
#include <stdio.h>
typedef struct { char * t;} aBuff;
int main(void)
{
aBuff *t;
int len,i;
len = 1000;
t = (aBuff*)malloc(len);
for (i=0; i<len; i++) {
t[i].t = (char*)malloc(255);
}
// freeing memory here...
system("pause");
return 0;
}
This code is to illustrate my trouble with malloc();
if len = 100, it work,
if len >= 1000, it crash.
I have to do up to 1 000 000 malloc in a loop, for my software (a raster to vector image converter).
So if someone know how to perform a "safe malloc" please tell me ;).
PS:
-- I have enough memory to run my code
-- if I put a lot of code in the loop (to speed down iterations)
it work (but this is not a solution)
Thank's,
SeKxX