I
Ian Collins
Hi Paavo
Well then I better ask how You get the console window to stay open
long enough to read the result, when doing a build and run.?
if You dont use something like getch();
Don't use windows!
Hi Paavo
Well then I better ask how You get the console window to stay open
long enough to read the result, when doing a build and run.?
if You dont use something like getch();
I test the code in a virtual machine, Fedora 15 witch in the Virtual
Box.
756M memory, 2G HZ.
It is slower than malloc, it's true. Unless reuse it.
Logically, std::string allocating a buffer is unlikely to be faster
than malloc for allocating memory. However, micro-benchmark tend to
by pretty irrelevant in real programs. They typically concentrate on
one single area while ignoring other potentially much more important
areas.
now, extend this generally, and note that most freely-available code is
either proprietary (can't be reused safely at all) or GPL,
and hence one
starts to see the problem, namely: why it is necessary for people to
write their own code to keep everything legal.
yes, there are MIT / BSD / ... projects, which allow more freely reusing
code without overbearing legal issues, but these projects are a relative
minority in FOSS land.
Well then I better ask how You get the console window to stay open
long enough to read the result, when doing a build and run.?
if You dont use something like getch();
Nobody said:Use something standard like cin.get();
Asger-P said:Well then I better ask how You get the console window to stay open
long enough to read the result, when doing a build and run.?
if You dont use something like getch();
Doesn't windows provide a command line?
Those are true (I know this because I have done a lot of C++ compiler
work), but frankly, people writing C++ parsers / compilers / etc, are
a miniscule fraction of the people using C++ for other tasks.
So what you have, basically, is harder work for a few, to make things
easier/better/safer for many.
Again, a pretty decent tradeoff.
[and given that I'm part of "the few", as well as part of the "many"
(I use C++ for many tasks), I think I have a pretty reasonable view of
this tradeoff. Indeed, for compiler writers, the additional
complexity isn't some sort of pure annoyance -- it's also in many ways
more interesting to work on (and for those writing their compiler in
C++, of course, a benefit)... :]
fair enough.
the problem is that I don't really have enough time/energy/... to
personally justify going through the work (all at once), though I may
eventually have it in a "one piece at a time" sense.
for interfacing between a script language and C++ at the C++ level, one
would probably need (in a basic sense):
ability to share classes (at least import them, to use C++ APIs directly
from the HLL, much harder is exporting classes to C++, and harder still
would be to allow mutual inheritance/overloading);
...
or, say for example, transparently interfacing C++ and an ECMAScript
variant (similar to JavaScript or ActionScript), ideally without making
awkward/arbitrary restrictions for one or the other (including semantic
mismatches).
And what compiler did you use and what compilation options did you
use?
gcc version 4.6.0 20110428 (Red Hat 4.6.0-6) (GCC)
compilation options? Â These are the key. Â Huge difference of behaviour
between -O0 and -O3.
you appear to be trying to justify copy-paste
this is a reason for writing stuff yourself. it is /not/ a reason for
copy-paste. If you've written the code yourself why not package it in
reusable form?
I possibly misunderstood what you were saying.
but not the standard libraries of either C or C++. There's also quite
a bit of BSD licensed code about.
we seem to be confusing different things (you seem to move the goal-
posts)
1. I asked why you would write your own sort rather than use qsort()
as a first pass.
2. you recomended copy-paste as a devlopment methodolgy. I think
it's hardly ever a reasonable thing to do. And is responsible for much
"software rot".
3. you (reasonably) use license problems as a reason to reinvent the
wheel.
3 is not a justification for either 1 or 2
of ones' own code...
copy/paste may well be justified in some cases, such as to avoid
creating a physical dependency between unrelated components, whereas
traditional code-reuse creates dependencies by extension.
What? By that logic, all libraries should be removed and their source
code copied instead. Lunacy.
If you are that paranoid about dependencies, put each function in a
header and include that...
Hi Paavo
Well then I better ask how You get the console window to stay open
long enough to read the result, when doing a build and run.?
if You dont use something like getch();
BGB said:FWIW, there are also "getc();" and "fgetc(stdin);" which are at least
more standard, but are also C-style, unlike "cin.get();" which is more
properly C++ (by whatever logic this makes sense, I don't get people
sometimes, as everything works either way, but whatever...).
but, stdio vs iostreams is another long and eventually pointless debate...
it is a tradeoff:
going this route (entirely) would tend to make many projects overly large.
but one still depends on the header, and depending on a header isn't
necessarily all that much better (however, I have done similar for a few
things, as the compiler tends to omit any static functions which are
never called, ...).
a partial advantage of headers is that they themselves can be more
readily copy-pasted and need not create additional dependencies, however
a partial disadvantage is that headers like this can potentially cause
horrible compile-time performance and a lot of unnecessary bloat, so it
is a tradeoff (it is bad enough when one already ends up with several MB
of included code just including many basic OS headers).
but, typically, one will copy/paste code, and use find/replace or sed to
re-scope it (replacing library/component prefixes or similar), and then
edit the code into the desired form for its use in a given component.
but, otherwise, one ends up with lots of centralized code that ends up
being depended on by lots of potentially unrelated things.
however, code may be centralized if it makes sense, say if there is
already a conceptually and mutually depended-on component, one may
consider migrating shared code to this location, provided it can be
sufficiently decoupled from its respective use-cases (does not have any
dependencies on the code which uses it, ...).
for example, memory management can be largely centralized (because most
code does roughly the same sorts of things with a memory manager).
likewise for things like filesystem interfacing, ...
things like parser logic are typically copy-pasted all over and
specialized for each use case, since it is far more difficult to
separate a parser from its use-cases (a parser for XML, one for C, and
one for ASM, and another for id/Valve/... style map files, ..., are each
sufficiently different to make having common code problematic, but are
sufficiently similar that it would be pointless to write the code
entirely from-scratch each time).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.