Re: No need to optimize in assembly anymore

From: Matt Taylor (para_at_tampabay.rr.com)
Date: 05/23/04


Date: Sun, 23 May 2004 00:12:16 +0000 (UTC)


"Bryan Parkoff" <bryan.nospam.parkoff@nospam.com> wrote in message
news:H%prc.9302$Hh.4606@fe1.texas.rr.com...
> Matt,
>
> I don't understand your point. You state that container classes or
just
> classes are slower than structs. If it is true that many assembler
> programmers and C (not C++) programmers are sticking with structs because
> they think that it can increase the performance better than classes. Is
it
> true?
<snip>

I am criticizing the *universal* use of container classes. I am saying that
std::vector is acceptable in some cases, but in other cases it is better to
create an array of 5 elements on the stack. (Aside: the one thing I do
dislike about STL containers is that they use C++ exception handling. With
MSVC, this results in bloated code.)

It is like the example I gave:

// ...
char *buf = new char[256];
FILE *fp;
sprintf(buf, "%s%s", path, filename);
fp = fopen(buf, "rb");
delete[] buf;
// ...

This code could be rewritten like this:
// ...
char buf[256];
FILE *fp;
sprintf(buf, "%s%s", path, filename);
fp = fopen(buf, "rb");
// ...

Fast code should avoid malloc & new whenever possible.

-Matt



Relevant Pages

  • Re: No need to optimize in assembly anymore
    ... I am criticizing the *universal* use of container classes. ... sprintf(buf, "%s%s", path, filename); ... deletebuf; ... char buf; ...
    (alt.lang.asm)
  • Re: memory leak?
    ... when he could instead use the more robust C++ container classes like ... explicit BYTE identifier is used, instead of 'char' (I don't know if the C++ ...
    (microsoft.public.vc.mfc)