Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: C Vs Asm i use for cat function |
| Date | 2012-08-05 21:04 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <jvmjq0$701$1@dont-email.me> (permalink) |
| References | <eb47af15-f8ff-4737-983d-3f54307c1081@googlegroups.com> <check-20120804172635@ram.dialup.fu-berlin.de> <501e0e0e$0$17946$4fafbaef@reader1.news.tin.it> <jvle1q$g1g$1@dont-email.me> <501eb144$0$13283$4fafbaef@reader2.news.tin.it> |
"io_x" <a@b.c.invalid> wrote in message
news:501eb144$0$13283$4fafbaef@reader2.news.tin.it...
>
> "BartC" <bc@freeuk.com> ha scritto nel messaggio
>> The nearest you can get in C is to forget about dynamic allocation, and
>> use
>> an upper limit for the size of the name. In lot of cases (99% of the ones
>> where I need to use string append), this is quite adequate, when you are
>> confident the results will not overflow:
>
> adeguate... there is no way, for the king, in informatic :)
A str_append() function as proposed by the OP, I tested to be about 3 times
*slower* than Python. Usually C is some fifty times faster than Python.
But mainly it introduces extra complexity, and opportunities for bugs and
memory leaks, if it is used where a fixed string size is viable.
>> #include <stdio.h>
>> #include <string.h>
>>
>> #define maxnamesize 250
>>
>> int main(void){
>> char name[maxnamesize];
>
> and if the size is >250? you have to change the number in the file...
> and if the string is going from extern?
If a fixed upper limit is not possible, then you use a different approach.
But only if necessary.
(What if you need to do arithmetic on two integers, do you worry about the
result not fitting into 32 or 64 bits? You don't use an arbitrary precision
integer library just in case! In Python of course numbers will just get
wider as needed. In C you need to use a more primitive approach, to retain
an advantage.)
--
Bartc
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Trying to figure out how to dynamically re-allocate strings while concatenating Shriramana Sharma <jamadagni@gmail.com> - 2012-08-04 07:12 -0700
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2012-08-04 16:17 +0200
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Xavier Roche <xroche@free.fr.NOSPAM.invalid> - 2012-08-04 16:22 +0200
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Shriramana Sharma <jamadagni@gmail.com> - 2012-08-04 07:25 -0700
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-04 16:04 +0100
Re: Trying to figure out how to dynamically re-allocate strings while concatenating "Heinrich Wolf" <invalid@invalid.invalid> - 2012-08-04 16:29 +0200
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-04 10:52 -0400
Re: Trying to figure out how to dynamically re-allocate strings while concatenating pete <pfiland@mindspring.com> - 2012-08-04 12:27 -0400
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-04 13:56 -0400
Re: Trying to figure out how to dynamically re-allocate strings while concatenating pete <pfiland@mindspring.com> - 2012-08-04 17:12 -0400
Re: Trying to figure out how to dynamically re-allocate strings while concatenating pete <pfiland@mindspring.com> - 2012-08-04 12:42 -0400
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-04 14:00 -0400
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Keith Thompson <kst-u@mib.org> - 2012-08-04 17:00 -0700
Re: Trying to figure out how to dynamically re-allocate strings while concatenating pete <pfiland@mindspring.com> - 2012-08-04 20:48 -0400
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Jens Gustedt <jens.gustedt@loria.fr> - 2012-08-05 09:22 +0200
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-05 12:49 +0100
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Jens Gustedt <jens.gustedt@loria.fr> - 2012-08-05 17:12 +0200
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Keith Thompson <kst-u@mib.org> - 2012-08-05 13:17 -0700
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-05 22:53 +0100
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Shriramana Sharma <jamadagni@gmail.com> - 2012-08-04 19:20 -0700
Re: C Vs Asm i use for cat function "io_x" <a@b.c.invalid> - 2012-08-05 08:15 +0200
Re: C Vs Asm i use for cat function "BartC" <bc@freeuk.com> - 2012-08-05 10:22 +0100
Re: C Vs Asm i use for cat function "Heinrich Wolf" <invalid@invalid.invalid> - 2012-08-05 17:00 +0200
Re: C Vs Asm i use for cat function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-08-05 16:20 +0100
Re: C Vs Asm i use for cat function "io_x" <a@b.c.invalid> - 2012-08-05 19:51 +0200
Re: C Vs Asm i use for cat function "BartC" <bc@freeuk.com> - 2012-08-05 21:04 +0100
Re: Trying to figure out how to dynamically re-allocate strings while concatenating Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-08-10 10:45 +0300
csiph-web