Quote:
Originally Posted by tygre
Here are some more details and a code snippet illustrating my problem:
Code:
#include <stdio.h>
int main()
{
printf("Hello World!\n");
void* ptr = malloc(1000);
// realloc(ptr, 10000);
free(ptr);
printf("Goodbye.\n");
return(0);
}
Please, let me know what you think!
Tygre
|
The gcc memory allocation routines seem to be a bit stuffed from what I've seen with calloc. The easiest thing to do is just re-implement relloc if that is what is causing you issues.
With calloc I found that if zero bytes were requested it would return NULL whereas other implementations behave the same way as malloc does when it is asked to allocate zero bytes (eg it doesn't return NULL).
This is the #define I use for the calloc issue:
Code:
#if !defined(FORCEINLINE) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
#define FORCEINLINE inline __attribute__((__always_inline__))
#endif
#ifndef FORCEINLINE
#define FORCEINLINE inline
#endif
// Fix 68k GCC issues with memory allocation/deallocation.
static FORCEINLINE void *callocEx(size_t num, size_t size) {
if (num == 0) {
num = 1;
}
return calloc(num, size);
}
#define calloc(num, size) callocEx(num, size)