Re: C++ vs Java "new" (no flame war please!)
- From: Lew <lew@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 01 Apr 2007 14:05:31 -0400
mlw wrote:
> (snipped description of custom 'new' operator)
Is there a way to create 10 to 100 million objects in Java with a reasonable
system configuration?
Sure, given the same considerations of available heap that you would have in the C++ world.
Let's assume you want to create N objects where N is the largest number of such objects that would fit in available memory.
List <Foo> stuff = new ArrayList <Foo> (N);
for ( int x = 0; x < N; ++x )
{
stuff.add( new Foo( getAString() ) );
}
doSomethingWith( stuff );
If you don't need them all in memory at once, it's even easier:
for ( int x = 0; x < N; ++x )
{
Foo foo = new Foo( getAString() );
doSomethingWith( foo );
}
I posit the 'getAString()' method as where you'd obtain the equivalent of the 'char * string' in the C++ example. I assumed you'd use a different string for each instance of Foo.
-- Lew
.
- Follow-Ups:
- References:
- C++ vs Java "new" (no flame war please!)
- From: mlw
- C++ vs Java "new" (no flame war please!)
- Prev by Date: looking for some hands on experience
- Next by Date: Re: C++ vs Java "new" (no flame war please!)
- Previous by thread: C++ vs Java "new" (no flame war please!)
- Next by thread: Re: C++ vs Java "new" (no flame war please!)
- Index(es):
Relevant Pages
|