Deutsch English Français Italiano |
<uu8rl0$v2o8$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: macro for fir list? Date: Sat, 30 Mar 2024 11:05:04 +0000 Organization: A noiseless patient Spider Lines: 22 Message-ID: <uu8rl0$v2o8$1@dont-email.me> References: <uu3s0m$3av2s$1@i2pn2.org> <uu88uo$qv85$3@dont-email.me> <uu8k48$3gr5r$1@i2pn2.org> <uu8leu$3gsq5$1@i2pn2.org> <uu8lqk$3gtd0$1@i2pn2.org> <uu8nju$3gvnj$1@i2pn2.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 30 Mar 2024 11:05:04 +0100 (CET) Injection-Info: dont-email.me; posting-host="2a39a4f275d14f8fd4fa1a15ff029e85"; logging-data="1018632"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BIVooi8nQDFWoFiIlOwi/" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:I1yToskLKLNIp2wEZHmrpiz+h0U= In-Reply-To: <uu8nju$3gvnj$1@i2pn2.org> Content-Language: en-GB Bytes: 1820 On 30/03/2024 09:56, fir wrote: >> > yet other example > > //bytes container > char* bytes = NULL; int bytes_size = 0; > void bytes_add(char val) { > (bytes=(char*)realloc(bytes,++bytes_size*sizeof(char)))[bytes_size-1]=val; } > void bytes_load(char* name) { FILE *f = fopen(name, "rb"); int c; > while((c=getc(f))!=EOF) bytes_add(c); fclose(f); } This is pretty inefficient. Loading an 8MB file this way takes 3 seconds, vs. 50ms to load it in one go. Loading the same 90KB file 10,000 times took 120 seconds, vs. 0.8 seconds even using a scripting language. 80% of the inefficiency is growing the buffer one byte at a time. The other 20% is reading the file one byte at a time.