[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays).
From: |
Daniel Glöckner |
Subject: |
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays). |
Date: |
Wed, 3 Oct 2007 14:49:53 +0200 |
User-agent: |
Mutt/1.4.2.1i |
On Wed, Oct 03, 2007 at 01:59:47AM -0500, Rob Landley wrote:
> It boils down to a funky call to alloca()...
One thing to note is that memory for VLAs is freed when the block ends.
GCC does this by saving the stack pointer before allocating the VLA and
restoring it at the end of the block.
This approach doesn't work if we mix VLAs with alloca.
#include <stdlib.h>
void f(char *,char *);
void g(int n)
{
while(n--) {
char p[n];
char *q=alloca(n*7);
f(p,q);
}
}
void h(int n)
{
while(n--) {
char *q=alloca(n*7);
f(q,q);
}
}
In g GCC will free the alloca'ed memory at the end of each iteration while
in h it will free the memory at the end of the function.
The GCC approach has the benefit that it won't force you to have 0,5TB of
memory if one calls
void e(int n) {
while(n--) {
char p[n];
f(p,p);
}
}
with n=1048576.
Daniel
- Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., (continued)
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Antti-Juhani Kaijanaho, 2007/10/03
- Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Rob Landley, 2007/10/03
- Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Antti-Juhani Kaijanaho, 2007/10/03
- Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Rob Landley, 2007/10/03
- Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Antti-Juhani Kaijanaho, 2007/10/03
- Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Rob Landley, 2007/10/04
- Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Antti-Juhani Kaijanaho, 2007/10/04
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays).,
Daniel Glöckner <=
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Rob Landley, 2007/10/03
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Simon 'corecode' Schubert, 2007/10/04
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Rob Landley, 2007/10/04
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Laurens Simonis, 2007/10/05
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Laurens Simonis, 2007/10/05
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Marc Andre Tanner, 2007/10/05
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Erik_L_Nelson, 2007/10/05
Re: [Tinycc-devel] Buiding binutils 2.17 (needs dynamic arrays)., Erik_L_Nelson, 2007/10/04