[ODE] Re: ALLOCA

jon klein jklein at spiderland.org
Thu Mar 4 15:29:47 MST 2004


On Mar 4, 2004, at 10:25 AM, Olivier Michel wrote:

> After compiling under Windows I realized that it is not possible to 
> make a realloc (under Linux, I was lucky since realloc didn't changed 
> the pointer, but it may change it and it does change it under 
> Windows). Realloc simply makes the previously returned pointers crazy 
> and the app crashes. So, no realloc :(. Instead a really big initial 
> memory chunk is allocated (I found 1MB to be a good compromise in my 
> case).

I use realloc under Windows without any problems (using MinGW) -- maybe 
the implementation of realloc you're using is faulty.

Allocating a static initial memory chunk doesn't avoid the problems in 
existing alloca solution, since it can run out.  And since the stack 
size can be changed at compile time, I think the alloca solution 
accomplishes the same thing.

Even if the stock realloc isn't working, it should be possible to do 
roughly the same thing manually:

    if (top > block_size) {
	int new_block_size;
	char *new_block;

      new_block_size = block_size + STACK_MEMORY_CHUNK_SIZE;

	new_block = malloc(new_block_size);
	bcopy(block, new_block, block_size);

	free(block);

	block = new_block;
	block_size = new_block_size;
    }

Thoughts?

- jon klein



More information about the ODE mailing list