Re: C++ vs Java "new" (no flame war please!)
- From: mlw <mlw@xxxxxxxxxxxxxx>
- Date: Mon, 02 Apr 2007 14:37:13 -0400
Mark Rafn wrote:
mlw <mlw@xxxxxxxxxxxxxx> wrote:
Take, for instance, this C++ construct:
void *foo::new(size_t size, char *string)
{
size_t cbstr = strlen(string)+1;
size_t cb = cbstr + size;
foo * t = (foo *) malloc(cb);
char * name = (char *) &t[1];
strcpy(name, string);
t->m_name = name;
}
The above example is a methodology that can be used to reduce the CPU and
memory overhead of malloc.
Trying not to flame C++ here, but I'm glad not to see very much of this
kind of code in Java.
Its not pretty, not at all, but it is the sort of code that can make the
difference between running or not running when necessary or withing the
time requirements. Fortunately, you can write it, test it, make sure it
works, then hide it in a library where newbees can't screw around and break
it.
You my argue that this is not a valid concern
In some apps, it is. If you're extremely sensitive to exact memory
allocation, or need hardware access that Java doesn't give you (say, to
SysV
shared memory or something), C++ is a good choice. I'd generally
recommend to do the specific sensitive bit in C++ and the rest in Java,
but it'll depend entirely on what the app actually does.
That's sort of why I posted the thread. I may need to do some "interesting"
things in Java and was kind of looking to see if anyone could come up with
a good trick or two.
Is there a way to create 10 to 100 million objects in Java with a
reasonable system configuration?
Any VM since 1.4 on modern hardware should not have a problem with this,
unless you're pretty time-sensitive.
To address the "time-sensitive" comment, many times I hear that the machines
are fast enough that you don't need to worry about performance, I have to
say this is the same argument for the 4 day work week. "Soon, we'll be
productive enough that we'll only have to work 4 days a week." That was the
dream and the myth. The problem with that line of thought is that as
capability is increased, so are expectations. I don't know about you, but
the 4 day work week hasn't come to my corner of the globe.
If you make a program that takes an hour to do something, and someone comes
along and writes one that takes 5 minutes, you lose, no matter what the
program is written in.
.
- Follow-Ups:
- Re: C++ vs Java "new" (no flame war please!)
- From: Mark Rafn
- Re: C++ vs Java "new" (no flame war please!)
- References:
- C++ vs Java "new" (no flame war please!)
- From: mlw
- Re: C++ vs Java "new" (no flame war please!)
- From: Mark Rafn
- C++ vs Java "new" (no flame war please!)
- Prev by Date: Re: C++ vs Java "new" (no flame war please!)
- Next by Date: pls fix with instructional comments
- Previous by thread: Re: C++ vs Java "new" (no flame war please!)
- Next by thread: Re: C++ vs Java "new" (no flame war please!)
- Index(es):
Relevant Pages
|
|