Re: C++ Speed Vs. Java
On Tue, 23 Jan 2007 08:07:04 CST, Gerhard Menzl wrote:
Ed Jensen wrote:
Deterministic destruction in Java isn't difficult. The pattern looks
something like this:
SomeType someType = null;
try {
someType = new SomeType();
// do some work
}
finally {
if (someType != null) {
someType.dispose();
someType = null;
}
}
I'll admit that it's less convenient than C++ objects created on the
stack:
{
SomeType someType;
// do some work
}
It's not just less convenient. It violates the time-honoured
principle "Once, and only once", and is therefore much more error-
prone and much less maintainable.
Exactly. I definitely include this consideration when labeling
software as "robust". In these days, I'm tightening my SHA class
templates with some security-oriented features (which should have been
there from the beginning, to be fair). In particular, I'm now always
zeroizing all buffers that might contain sensitive data with a simple
function template like this:
template< typename T, std::size_t n >
void secure_fill( volatile T ( &arr )[ n ], T val = T() )
{
for( std::size_t i( 0 ); i < n; ++i )
arr[ i ] = val;
}
However on a first application of this I ended up calling secure_fill
twice for each SHA algorithm, one for the message block and one for
the "schedule", and they are two calls to be inserted manually. That's
not good, and I'm currently implementing some helpers to automate
this. This is one of the greatest strengths of C++: you can put almost
anything in a reusable form and never repeat yourself. If were being
asked off-hand to cite two universal laws of data processing (other
than the fundamental Koenig-theorem of software engineering :-)) I'd
say: 1) two copies that must be kept in sync, won't be in sync, soon
or later 2) if you have to check for the same things manually over and
over you'll make a mistake, soon or later. In Java I didn't see how to
avoid the latter.
--
HELP: many of this group's participants might know that I'm the legit
owner of
~~~~ the yahoo account with id 'gennaro_prota'; I'd be immensely
grateful to
anyone who might help me gaining access to it again (note that
I'm now
using the id 'gennaro.prota'). Thanks!
{ Perhaps try <url: https://edit.yahoo.com/forgot>, if you haven't
already? -mod }
Genny.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]